Revert "[Tizen] Added 'make clean' on each profile build."
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / ecore-x-event-handler.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_X.h>
28
29 #include <X11/Xlib.h>
30 #include <X11/extensions/XInput2.h>
31 #include <X11/extensions/XI2.h>
32
33 #include <cstring>
34
35 #include <sys/time.h>
36
37 #ifndef DALI_PROFILE_UBUNTU
38 #include <vconf.h>
39 #include <vconf-keys.h>
40 #endif // DALI_PROFILE_UBUNTU
41
42 #ifdef DALI_ELDBUS_AVAILABLE
43 #include <Eldbus.h>
44 #endif // DALI_ELDBUS_AVAILABLE
45
46 #include <dali/public-api/common/vector-wrapper.h>
47 #include <dali/public-api/events/touch-point.h>
48 #include <dali/public-api/events/key-event.h>
49 #include <dali/public-api/events/wheel-event.h>
50 #include <dali/integration-api/debug.h>
51 #include <dali/integration-api/events/key-event-integ.h>
52 #include <dali/integration-api/events/touch-event-integ.h>
53 #include <dali/integration-api/events/hover-event-integ.h>
54 #include <dali/integration-api/events/wheel-event-integ.h>
55 #include <dali/devel-api/events/key-event-devel.h>
56
57 // INTERNAL INCLUDES
58 #include <events/gesture-manager.h>
59 #include <window-render-surface.h>
60 #include <clipboard-impl.h>
61 #include <key-impl.h>
62 #include <physical-keyboard-impl.h>
63 #include <style-monitor-impl.h>
64 #include <base/core-event-interface.h>
65
66 namespace Dali
67 {
68
69 namespace Internal
70 {
71
72 namespace Adaptor
73 {
74
75 #if defined(DEBUG_ENABLED)
76 namespace
77 {
78 Integration::Log::Filter* gTouchEventLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_TOUCH");
79 Integration::Log::Filter* gClientMessageLogFilter  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_CLIENT_MESSAGE");
80 Integration::Log::Filter* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
81 Integration::Log::Filter* gImfLogging  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
82 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
83 } // unnamed namespace
84 #endif
85
86
87 namespace
88 {
89
90 const char * DETENT_DEVICE_NAME = "tizen_detent";
91 const std::string DEFAULT_DEVICE_NAME = "";
92 const DevelKeyEvent::DeviceClass::Type DEFAULT_DEVICE_CLASS = DevelKeyEvent::DeviceClass::NONE;
93
94 // DBUS accessibility
95 #define A11Y_BUS "org.a11y.Bus"
96 #define A11Y_INTERFACE "org.a11y.Bus"
97 #define A11Y_PATH "/org/a11y/bus"
98 #define A11Y_GET_ADDRESS "GetAddress"
99 #define BUS "com.samsung.EModule"
100 #define INTERFACE "com.samsung.GestureNavigation"
101 #define PATH "/com/samsung/GestureNavigation"
102 #define SIGNAL "GestureDetected"
103
104 #ifndef DALI_PROFILE_UBUNTU
105 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
106 #endif // DALI_PROFILE_UBUNTU
107
108 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
109
110 #ifndef DALI_PROFILE_UBUNTU
111 const char * CLIPBOARD_ATOM                = "CBHM_MSG";
112 const char * CLIPBOARD_SET_OWNER_MESSAGE   = "SET_OWNER";
113 #endif // DALI_PROFILE_UBUNTU
114
115 /// The atoms required by Ecore for Drag & Drop behaviour.
116 Ecore_X_Atom DRAG_AND_DROP_ATOMS[] =
117 {
118   ECORE_X_ATOM_XDND_ACTION_COPY,
119 };
120
121 /// The types that we support.
122 const char * DRAG_AND_DROP_TYPES[] =
123 {
124   ECORE_X_SELECTION_TARGET_UTF8_STRING,
125 };
126
127 const unsigned int DRAG_AND_DROP_ATOMS_NUMBER = sizeof( DRAG_AND_DROP_ATOMS ) / sizeof( Ecore_X_Atom );
128 const unsigned int DRAG_AND_DROP_TYPES_NUMBER = sizeof( DRAG_AND_DROP_TYPES ) / sizeof( const char * );
129
130 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
131
132 #ifdef DALI_ELDBUS_AVAILABLE
133 // DBus gesture string matching lists.
134 // TODO: This needs moving to its own module.
135 const char * ElDBusAccessibilityFingerCountStrings[] =
136 {
137   "OneFinger",
138   "TwoFingers",
139   "ThreeFingers"
140 };
141 const unsigned int FingerCountStringsTotal = sizeof( ElDBusAccessibilityFingerCountStrings ) / sizeof( ElDBusAccessibilityFingerCountStrings[0] );
142 enum GestureType
143 {
144   GESTURE_TYPE_NONE,
145   GESTURE_TYPE_HOVER,
146   GESTURE_TYPE_SINGLE_TAP,
147   GESTURE_TYPE_DOUBLE_TAP,
148   GESTURE_TYPE_TRIPLE_TAP
149 };
150 struct GestureTypeTable
151 {
152   const char* name;
153   const GestureType type;
154 };
155 GestureTypeTable ElDBusAccessibilityFullEventTypeStrings[] =
156 {
157   { "Hover",     GESTURE_TYPE_HOVER      },
158   { "SingleTap", GESTURE_TYPE_SINGLE_TAP },
159   { "DoubleTap", GESTURE_TYPE_DOUBLE_TAP },
160   { "TripleTap", GESTURE_TYPE_TRIPLE_TAP }
161 };
162 const unsigned int FullEventTypeStringsTotal = sizeof( ElDBusAccessibilityFullEventTypeStrings ) / sizeof( ElDBusAccessibilityFullEventTypeStrings[0] );
163 enum SubGestureType
164 {
165   SUB_GESTURE_TYPE_NONE,
166   SUB_GESTURE_TYPE_FLICK
167 };
168 struct SubGestureTypeTable
169 {
170   const char* name;
171   const SubGestureType type;
172 };
173 SubGestureTypeTable ElDBusAccessibilityDirectionalEventTypeStrings[] =
174 {
175   { "Flick", SUB_GESTURE_TYPE_FLICK }
176 };
177 const unsigned int DirectionalEventTypeStringsTotal = sizeof( ElDBusAccessibilityDirectionalEventTypeStrings ) / sizeof( ElDBusAccessibilityDirectionalEventTypeStrings[0] );
178 enum GestureDirection
179 {
180   GESTURE_DIRECTION_NONE,
181   GESTURE_DIRECTION_UP,
182   GESTURE_DIRECTION_DOWN,
183   GESTURE_DIRECTION_LEFT,
184   GESTURE_DIRECTION_RIGHT,
185   GESTURE_DIRECTION_UP_RETURN,
186   GESTURE_DIRECTION_DOWN_RETURN,
187   GESTURE_DIRECTION_LEFT_RETURN,
188   GESTURE_DIRECTION_RIGHT_RETURN
189 };
190 struct GestureDirectionTable
191 {
192         const char* name;
193         const GestureDirection direction;
194 };
195 GestureDirectionTable ElDBusAccessibilityDirectionStrings[] =
196 {
197   { "Up",           GESTURE_DIRECTION_UP           },
198   { "Down",         GESTURE_DIRECTION_DOWN         },
199   { "Left",         GESTURE_DIRECTION_LEFT         },
200   { "Right",        GESTURE_DIRECTION_RIGHT        },
201   { "UpReturn",     GESTURE_DIRECTION_UP_RETURN    },
202   { "DownReturn",   GESTURE_DIRECTION_DOWN_RETURN  },
203   { "LeftReturn",   GESTURE_DIRECTION_LEFT_RETURN  },
204   { "RightReturn",  GESTURE_DIRECTION_RIGHT_RETURN }
205 };
206 const unsigned int DirectionStringsTotal = sizeof( ElDBusAccessibilityDirectionStrings ) / sizeof( ElDBusAccessibilityDirectionStrings[0] );
207 #endif // DALI_ELDBUS_AVAILABLE
208
209 /**
210  * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
211  * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
212  * @param[in] ecoreModifier the Ecore_Event_Modifier input.
213  * @return the Ecore_IMF_Keyboard_Modifiers output.
214  */
215 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
216 {
217    int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE );  // If no other matches returns NONE.
218
219
220    if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT )  // enums from ecore_input/Ecore_Input.h
221    {
222      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;  // enums from ecore_imf/ecore_imf.h
223    }
224
225    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
226    {
227      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
228    }
229
230    if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
231    {
232      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
233    }
234
235    if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
236    {
237      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
238    }
239
240    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
241    {
242      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
243    }
244
245    return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
246 }
247
248
249 // Copied from x server
250 static unsigned int GetCurrentMilliSeconds(void)
251 {
252   struct timeval tv;
253
254   struct timespec tp;
255   static clockid_t clockid;
256
257   if (!clockid)
258   {
259 #ifdef CLOCK_MONOTONIC_COARSE
260     if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
261       (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
262     {
263       clockid = CLOCK_MONOTONIC_COARSE;
264     }
265     else
266 #endif
267     if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
268     {
269       clockid = CLOCK_MONOTONIC;
270     }
271     else
272     {
273       clockid = ~0L;
274     }
275   }
276   if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
277   {
278     return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
279   }
280
281   gettimeofday(&tv, NULL);
282   return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
283 }
284
285 } // unnamed namespace
286
287 // Impl to hide EFL implementation.
288 struct EventHandler::Impl
289 {
290   // Construction & Destruction
291
292   /**
293    * Constructor
294    */
295   Impl( EventHandler* handler, Ecore_X_Window window )
296   : mHandler( handler ),
297     mEcoreEventHandler(),
298     mWindow( window ),
299     mXiDeviceId( 0 )
300 #ifdef DALI_ELDBUS_AVAILABLE
301   , mSessionConnection( NULL ),
302     mA11yConnection( NULL )
303 #endif
304   {
305     // Only register for touch and key events if we have a window
306     if ( window != 0 )
307     {
308       // Register Touch events
309       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,  EcoreEventMouseButtonDown, handler ) );
310       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,    EcoreEventMouseButtonUp,   handler ) );
311       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,         EcoreEventMouseButtonMove, handler ) );
312       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT,          EcoreEventMouseButtonUp,   handler ) ); // process mouse out event like up event
313
314       // Register Mouse wheel events
315       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,        EcoreEventMouseWheel,      handler ) );
316
317       // Register Key events
318       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,           EcoreEventKeyDown,         handler ) );
319       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP,             EcoreEventKeyUp,           handler ) );
320
321       // Register Focus events
322       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_IN,  EcoreEventWindowFocusIn,   handler ) );
323       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_FOCUS_OUT, EcoreEventWindowFocusOut,  handler ) );
324
325       // Register Window damage events
326       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DAMAGE,    EcoreEventWindowDamaged, handler ) );
327
328       // Enable Drag & Drop and register DnD events
329       ecore_x_dnd_aware_set( window, EINA_TRUE );
330       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_ENTER,       EcoreEventDndEnter,            handler) );
331       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_POSITION,    EcoreEventDndPosition,         handler) );
332       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_LEAVE,       EcoreEventDndLeave,            handler) );
333       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_DROP,        EcoreEventDndDrop,             handler) );
334       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_FINISHED,    EcoreEventDndFinished,         handler) );
335       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_XDND_STATUS,      EcoreEventDndStatus,           handler) );
336
337       // Register Client message events - accessibility etc.
338       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE,  EcoreEventClientMessage, handler ) );
339
340       // Register Selection event - clipboard selection, Drag & Drop selection etc.
341       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_CLEAR, EcoreEventSelectionClear, handler ) );
342       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_SELECTION_NOTIFY, EcoreEventSelectionNotify, handler ) );
343
344       // Initialize Xi2 system
345       Display* display = static_cast< Display* >(ecore_x_display_get());
346       Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
347       int opcode = 0, event = 0, error = 0;
348       int major = XI_2_Major;
349       int minor = XI_2_Minor;
350       int deviceCount = 0;
351       XIEventMask xiEventMask;
352
353       // Check if X input extension available
354       if( XQueryExtension( display, "XInputExtension", &opcode, &event, &error ) )
355       {
356         // We support version 2.0
357         if( XIQueryVersion( display, &major, &minor ) != BadRequest )
358         {
359           xiEventMask.deviceid = XIAllDevices;
360
361           // Check device id
362           bool match = false;
363           XIDeviceInfo* deviceInfo = NULL;
364           deviceInfo = XIQueryDevice( display, XIAllDevices, &deviceCount );
365
366           for( int i = 0; i < deviceCount; i++ )
367           {
368             if( !strncmp( deviceInfo[i].name, DETENT_DEVICE_NAME, strlen( DETENT_DEVICE_NAME ) ) )
369             {
370               xiEventMask.deviceid = deviceInfo[i].deviceid;
371               match = true;
372               break;
373             }
374           }
375
376           if( match )
377           {
378             mXiDeviceId = xiEventMask.deviceid;
379
380             // SelectXi2Event
381             Dali::Vector< unsigned char > mask;
382             std::size_t xiMaskLen = XIMaskLen( XI_LASTEVENT );
383             mask.Reserve( xiMaskLen );
384             xiEventMask.mask = mask.Begin();
385
386             XISetMask( xiEventMask.mask, XI_RawMotion );
387
388             xiEventMask.mask_len = xiMaskLen * sizeof( unsigned char );
389
390             int ret = XISelectEvents( display, rootWindow, &xiEventMask, 1 );
391             if( ret == 0 )
392             {
393               // Register custom wheel events
394               mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_X_EVENT_GENERIC, EcoreEventCustomWheel, handler ) );
395             }
396             else
397             {
398               DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to Select Events\n" );
399             }
400           }
401
402           if( deviceInfo != NULL )
403           {
404             XIFreeDeviceInfo( deviceInfo );
405           }
406         }
407         else
408         {
409           DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XI Version\n" );
410         }
411       }
412       else
413       {
414         DALI_LOG_INFO( gImfLogging, Debug::General, "Failed to query XInputExtension\n" );
415       }
416
417 #ifndef DALI_PROFILE_UBUNTU
418       // Register Vconf notify - font name, font size and style
419       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, handler );
420       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
421 #endif // DALI_PROFILE_UBUNTU
422
423 #ifdef DALI_ELDBUS_AVAILABLE
424
425       // Initialize ElDBus.
426       DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
427       eldbus_init();
428
429       mSessionConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SESSION );
430
431       Eldbus_Object *a11yObject = eldbus_object_get( mSessionConnection, A11Y_BUS, A11Y_PATH );
432       Eldbus_Proxy *elDBusManager = eldbus_proxy_get( a11yObject, A11Y_INTERFACE );
433
434       // Pass in handler in the cb_data field so we can access the accessibility adaptor within the callback.
435       eldbus_proxy_call( elDBusManager, A11Y_GET_ADDRESS, EcoreElDBusInitialisation, handler, -1, "" );
436
437       DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
438
439 #endif // DALI_ELDBUS_AVAILABLE
440     }
441   }
442
443   /**
444    * Destructor
445    */
446   ~Impl()
447   {
448 #ifndef DALI_PROFILE_UBUNTU
449     vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
450     vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
451 #endif // DALI_PROFILE_UBUNTU
452
453     for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
454     {
455       ecore_event_handler_del( *iter );
456     }
457
458 #ifdef DALI_ELDBUS_AVAILABLE
459     // Close down ElDBus
460     if( mA11yConnection )
461     {
462       eldbus_connection_unref( mA11yConnection );
463     }
464
465     if( mSessionConnection )
466     {
467       eldbus_connection_unref( mSessionConnection );
468     }
469
470     eldbus_shutdown();
471 #endif // DALI_ELDBUS_AVAILABLE
472   }
473
474   // Static methods
475
476   /////////////////////////////////////////////////////////////////////////////////////////////////
477   // Touch Callbacks
478   /////////////////////////////////////////////////////////////////////////////////////////////////
479
480   /**
481    * Called when a touch down is received.
482    */
483   static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
484   {
485     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
486     EventHandler* handler( (EventHandler*)data );
487
488     if ( touchEvent->window == handler->mImpl->mWindow )
489     {
490       PointState::Type state ( PointState::DOWN );
491
492       // Check if the buttons field is set and ensure it's the primary touch button.
493       // If this event was triggered by buttons other than the primary button (used for touch), then
494       // just send an interrupted event to Core.
495       if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
496       {
497         state = PointState::INTERRUPTED;
498       }
499
500       Integration::Point point;
501       point.SetDeviceId( touchEvent->multi.device );
502       point.SetState( state );
503       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
504       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
505       point.SetPressure( touchEvent->multi.pressure );
506       point.SetAngle( Degree( touchEvent->multi.angle ) );
507       handler->SendEvent( point, touchEvent->timestamp );
508     }
509
510     return ECORE_CALLBACK_PASS_ON;
511   }
512
513   /**
514    * Called when a touch up is received.
515    */
516   static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
517   {
518     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
519     EventHandler* handler( (EventHandler*)data );
520
521     if ( touchEvent->window == handler->mImpl->mWindow )
522     {
523       Integration::Point point;
524       point.SetDeviceId( touchEvent->multi.device );
525       point.SetState( PointState::UP );
526       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
527       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
528       point.SetPressure( touchEvent->multi.pressure );
529       point.SetAngle( Degree( touchEvent->multi.angle ) );
530       handler->SendEvent( point, touchEvent->timestamp );
531     }
532
533     return ECORE_CALLBACK_PASS_ON;
534   }
535
536   /**
537    * Called when a touch motion is received.
538    */
539   static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
540   {
541     Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
542     EventHandler* handler( (EventHandler*)data );
543
544     if ( touchEvent->window == handler->mImpl->mWindow )
545     {
546       Integration::Point point;
547       point.SetDeviceId( touchEvent->multi.device );
548       point.SetState( PointState::MOTION );
549       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
550       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
551       point.SetPressure( touchEvent->multi.pressure );
552       point.SetAngle( Degree( touchEvent->multi.angle ) );
553       handler->SendEvent( point, touchEvent->timestamp );
554     }
555
556     return ECORE_CALLBACK_PASS_ON;
557   }
558
559   /////////////////////////////////////////////////////////////////////////////////////////////////
560   // Wheel Callbacks
561   /////////////////////////////////////////////////////////////////////////////////////////////////
562
563   /**
564    * Called when a mouse wheel is received.
565    */
566   static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
567   {
568     Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
569
570     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 );
571
572     EventHandler* handler( (EventHandler*)data );
573     if ( mouseWheelEvent->window == handler->mImpl->mWindow )
574     {
575       WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
576       handler->SendWheelEvent( wheelEvent );
577     }
578     return ECORE_CALLBACK_PASS_ON;
579   }
580
581   /**
582    * Called when a custom wheel is received.
583    */
584   static Eina_Bool EcoreEventCustomWheel( void* data, int type, void* event )
585   {
586     Ecore_X_Event_Generic *genericEvent( (Ecore_X_Event_Generic*)event );
587     EventHandler* handler( (EventHandler*)data );
588
589     switch( genericEvent->evtype )
590     {
591       case XI_RawMotion:
592       {
593         XIRawEvent* xiRawEvent = static_cast< XIRawEvent* >( genericEvent->data );
594         unsigned int timeStamp = 0;
595
596         if( xiRawEvent->deviceid != handler->mImpl->mXiDeviceId )
597         {
598           return ECORE_CALLBACK_PASS_ON;
599         }
600
601         // X(0): rotate: NOT USED
602         // Y(1): timestamp
603         // Z(2): direction
604
605         double* value = xiRawEvent->raw_values;
606
607         if( XIMaskIsSet( xiRawEvent->valuators.mask, 1) )
608         {
609           timeStamp = static_cast< unsigned int >( *(value + 1) );
610         }
611
612         if( XIMaskIsSet( xiRawEvent->valuators.mask, 2) )
613         {
614           // if z == 1, clockwise
615           // otherwise counter-clockwise
616           int z = static_cast< int >( *(value + 2) );
617
618           // In DALi, positive value means clockwise, and negative value means counter-clockwise
619           if( z == 0 )
620           {
621             z = -1;
622           }
623
624           DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventCustomWheel: z: %d\n", z );
625
626           WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), z, timeStamp );
627           handler->SendWheelEvent( wheelEvent );
628         }
629         break;
630       }
631       default:
632       {
633         break;
634       }
635     }
636
637     return ECORE_CALLBACK_PASS_ON;
638   }
639
640   /////////////////////////////////////////////////////////////////////////////////////////////////
641   // Key Callbacks
642   /////////////////////////////////////////////////////////////////////////////////////////////////
643
644   /**
645    * Called when a key down is received.
646    */
647   static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
648   {
649     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
650
651     EventHandler* handler( (EventHandler*)data );
652     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
653     bool eventHandled( false );
654
655     // If a device key then skip ecore_imf_context_filter_event.
656     if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
657     {
658       Ecore_IMF_Context* imfContext = NULL;
659       Dali::ImfManager imfManager( ImfManager::Get() );
660       if ( imfManager )
661       {
662         imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
663       }
664
665       if ( imfContext )
666       {
667         // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
668         Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
669         ecoreKeyDownEvent.keyname   = keyEvent->keyname;
670         ecoreKeyDownEvent.key       = keyEvent->key;
671         ecoreKeyDownEvent.string    = keyEvent->string;
672         ecoreKeyDownEvent.compose   = keyEvent->compose;
673         ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
674         ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
675         ecoreKeyDownEvent.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
676 #ifdef ECORE_IMF_1_13
677         ecoreKeyDownEvent.dev_name  = "";
678         ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
679         ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
680 #endif // ECORE_IMF_1_13
681
682         eventHandled = ecore_imf_context_filter_event( imfContext,
683                                                        ECORE_IMF_EVENT_KEY_DOWN,
684                                                        (Ecore_IMF_Event *) &ecoreKeyDownEvent );
685
686         // If the event has not been handled by IMF then check if we should reset our IMF context
687         if( !eventHandled )
688         {
689           if ( !strcmp( keyEvent->keyname, "Escape"   ) ||
690                !strcmp( keyEvent->keyname, "Return"   ) ||
691                !strcmp( keyEvent->keyname, "KP_Enter" ) )
692           {
693             ecore_imf_context_reset( imfContext );
694           }
695         }
696       }
697     }
698
699     // If the event wasn't handled then we should send a key event.
700     if ( !eventHandled )
701     {
702       if ( keyEvent->window == handler->mImpl->mWindow )
703       {
704         std::string keyName( keyEvent->keyname );
705         std::string keyString( "" );
706         int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
707         int modifier( keyEvent->modifiers );
708         unsigned long time = keyEvent->timestamp;
709
710         // Ensure key event string is not NULL as keys like SHIFT have a null string.
711         if ( keyEvent->string )
712         {
713           keyString = keyEvent->string;
714         }
715
716         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
717         handler->SendEvent( keyEvent );
718       }
719     }
720
721     return ECORE_CALLBACK_PASS_ON;
722   }
723
724   /**
725    * Called when a key up is received.
726    */
727   static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
728   {
729     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp \n" );
730
731     EventHandler* handler( (EventHandler*)data );
732     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
733     bool eventHandled( false );
734
735     // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
736     if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
737     {
738       Ecore_IMF_Context* imfContext = NULL;
739       Dali::ImfManager imfManager( ImfManager::Get() );
740       if ( imfManager )
741       {
742         imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
743       }
744
745       if ( imfContext )
746       {
747         // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
748         Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
749         ecoreKeyUpEvent.keyname   = keyEvent->keyname;
750         ecoreKeyUpEvent.key       = keyEvent->key;
751         ecoreKeyUpEvent.string    = keyEvent->string;
752         ecoreKeyUpEvent.compose   = keyEvent->compose;
753         ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
754         ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
755         ecoreKeyUpEvent.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
756 #ifdef ECORE_IMF_1_13
757         ecoreKeyUpEvent.dev_name  = "";
758 #endif // ECORE_IMF_1_13
759
760         eventHandled = ecore_imf_context_filter_event( imfContext,
761                                                        ECORE_IMF_EVENT_KEY_UP,
762                                                        (Ecore_IMF_Event *) &ecoreKeyUpEvent );
763       }
764     }
765
766     // If the event wasn't handled then we should send a key event.
767     if ( !eventHandled )
768     {
769       if ( keyEvent->window == handler->mImpl->mWindow )
770       {
771         std::string keyName( keyEvent->keyname );
772         std::string keyString( "" );
773         int keyCode = ecore_x_keysym_keycode_get(keyEvent->keyname);
774         int modifier( keyEvent->modifiers );
775         unsigned long time( keyEvent->timestamp );
776
777         // Ensure key event string is not NULL as keys like SHIFT have a null string.
778         if ( keyEvent->string )
779         {
780           keyString = keyEvent->string;
781         }
782
783         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, DEFAULT_DEVICE_CLASS );
784
785         handler->SendEvent( keyEvent );
786       }
787     }
788
789     return ECORE_CALLBACK_PASS_ON;
790   }
791
792   /////////////////////////////////////////////////////////////////////////////////////////////////
793   // Window Callbacks
794   /////////////////////////////////////////////////////////////////////////////////////////////////
795
796   /**
797    * Called when the window gains focus.
798    */
799   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
800   {
801     Ecore_X_Event_Window_Focus_In* focusInEvent( (Ecore_X_Event_Window_Focus_In*)event );
802     EventHandler* handler( (EventHandler*)data );
803
804     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
805
806     // If the window gains focus and we hid the keyboard then show it again.
807     if ( focusInEvent->win == handler->mImpl->mWindow )
808     {
809       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
810
811       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
812       {
813         Dali::ImfManager imfManager( ImfManager::Get() );
814         if ( imfManager )
815         {
816           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
817           if( imfManagerImpl.RestoreAfterFocusLost() )
818           {
819             imfManagerImpl.Activate();
820           }
821         }
822       }
823       // No need to connect callbacks as KeyboardStatusChanged will be called.
824     }
825
826     return ECORE_CALLBACK_PASS_ON;
827   }
828
829   /**
830    * Called when the window loses focus.
831    */
832   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
833   {
834     Ecore_X_Event_Window_Focus_Out* focusOutEvent( (Ecore_X_Event_Window_Focus_Out*)event );
835     EventHandler* handler( (EventHandler*)data );
836
837     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
838
839     // If the window loses focus then hide the keyboard.
840     if ( focusOutEvent->win == handler->mImpl->mWindow )
841     {
842       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
843       {
844         Dali::ImfManager imfManager( ImfManager::Get() );
845         if ( imfManager )
846         {
847           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
848           if( imfManagerImpl.RestoreAfterFocusLost() )
849           {
850             imfManagerImpl.Deactivate();
851           }
852         }
853       }
854
855       // Clipboard don't support that whether clipboard is shown or not. Hide clipboard.
856       Dali::Clipboard clipboard = Clipboard::Get();
857       clipboard.HideClipboard();
858     }
859
860     return ECORE_CALLBACK_PASS_ON;
861   }
862
863   /**
864    * Called when the window is damaged.
865    */
866   static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
867   {
868     Ecore_X_Event_Window_Damage* windowDamagedEvent( (Ecore_X_Event_Window_Damage*)event );
869     EventHandler* handler( (EventHandler*)data );
870
871     if( windowDamagedEvent->win == handler->mImpl->mWindow )
872     {
873       DamageArea area;
874       area.x = windowDamagedEvent->x;
875       area.y = windowDamagedEvent->y;
876       area.width = windowDamagedEvent->w;
877       area.height = windowDamagedEvent->h;
878
879       handler->SendEvent( area );
880     }
881
882     return ECORE_CALLBACK_PASS_ON;
883   }
884
885   /**
886    * Called when the window properties are changed.
887    * We are only interested in the font change.
888    */
889
890
891   /////////////////////////////////////////////////////////////////////////////////////////////////
892   // Drag & Drop Callbacks
893   /////////////////////////////////////////////////////////////////////////////////////////////////
894
895   /**
896    * Called when a dragged item enters our window's bounds.
897    * This is when items are dragged INTO our window.
898    */
899   static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
900   {
901     DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
902
903     Ecore_X_Event_Xdnd_Enter* enterEvent( (Ecore_X_Event_Xdnd_Enter*) event );
904     EventHandler* handler( (EventHandler*)data );
905     Ecore_X_Window window ( handler->mImpl->mWindow );
906
907     if ( enterEvent->win == window )
908     {
909       DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
910
911       // Check whether the Drag & Drop detector has Drag & Drop behaviour enabled before we accept.
912       if ( dndDetector && dndDetector->IsEnabled() )
913       {
914         // Tell Ecore that we want to enable drop in the entire window.
915         Ecore_X_Rectangle rect;
916         rect.x = rect.y = 0;
917         ecore_x_window_geometry_get( window, NULL, NULL, (int*)&rect.width, (int*)&rect.height );
918
919         // Tell Ecore that we are able to process a drop.
920         ecore_x_dnd_send_status( EINA_TRUE, EINA_FALSE, rect, ECORE_X_ATOM_XDND_DROP );
921
922         // Register the required atoms and types.
923         ecore_x_dnd_actions_set( window, DRAG_AND_DROP_ATOMS, DRAG_AND_DROP_ATOMS_NUMBER );
924         ecore_x_dnd_types_set(   window, DRAG_AND_DROP_TYPES, DRAG_AND_DROP_TYPES_NUMBER );
925
926         // Request to get the content from Ecore.
927         ecore_x_selection_xdnd_request( window, ECORE_X_SELECTION_TARGET_UTF8_STRING );
928
929         DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndEnter: Requesting Drag & Drop\n" );
930
931         // Clear the previous content
932         dndDetector->ClearContent();
933
934         // Emit the entered signal
935         dndDetector->EmitEnteredSignal();
936       }
937     }
938
939     return ECORE_CALLBACK_PASS_ON;
940   }
941
942   /**
943    * Called when a dragged item is moved within our window.
944    * This is when items are dragged INTO our window.
945    */
946   static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
947   {
948     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
949
950     Ecore_X_Event_Xdnd_Position* positionEvent( (Ecore_X_Event_Xdnd_Position*) event );
951     EventHandler* handler( (EventHandler*)data );
952
953     if ( positionEvent->win == handler->mImpl->mWindow )
954     {
955       DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
956
957       // If we have a detector then update its latest position.
958       if ( dndDetector )
959       {
960         DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndPosition: position ( %d x %d )\n", positionEvent->position.x, positionEvent->position.y );
961         dndDetector->SetPosition( Vector2( positionEvent->position.x, positionEvent->position.y ));
962         dndDetector->EmitMovedSignal();
963       }
964     }
965
966     return ECORE_CALLBACK_PASS_ON;
967   }
968
969   /**
970    * Called when a dragged item leaves our window's bounds.
971    * This is when items are dragged INTO our window.
972    */
973   static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
974   {
975     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
976
977     Ecore_X_Event_Xdnd_Leave* leaveEvent( (Ecore_X_Event_Xdnd_Leave*) event );
978     EventHandler* handler( (EventHandler*)data );
979
980     if ( leaveEvent->win == handler->mImpl->mWindow )
981     {
982       DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
983
984       // If we have a detector then clear its content and emit the exited-signal. Also tell Ecore that we have finished.
985       if ( dndDetector )
986       {
987         dndDetector->ClearContent();
988         dndDetector->EmitExitedSignal();
989
990         ecore_x_dnd_send_finished();
991
992         DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndLeave: Finished\n" );
993       }
994     }
995
996     return ECORE_CALLBACK_PASS_ON;
997   }
998
999   /**
1000    * Called when the dragged item is dropped within our window's bounds.
1001    * This is when items are dragged INTO our window.
1002    */
1003   static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
1004   {
1005     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
1006
1007     Ecore_X_Event_Xdnd_Drop* dropEvent ( (Ecore_X_Event_Xdnd_Drop*) event);
1008     EventHandler* handler( (EventHandler*)data );
1009
1010     if ( dropEvent->win == handler->mImpl->mWindow )
1011     {
1012       DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1013
1014       // Something has been dropped, inform the detector (if we have one) and tell Ecore that we have finished.
1015       if ( dndDetector )
1016       {
1017         DALI_LOG_INFO(gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: position ( %d x %d )\n", dropEvent->position.x, dropEvent->position.y );
1018
1019         dndDetector->SetPosition( Vector2( dropEvent->position.x, dropEvent->position.y ) );
1020         dndDetector->EmitDroppedSignal();
1021         ecore_x_dnd_send_finished();
1022
1023         DALI_LOG_INFO( gDragAndDropLogFilter, Debug::General, "EcoreEventDndDrop: Finished\n" );
1024       }
1025     }
1026
1027     return ECORE_CALLBACK_PASS_ON;
1028   }
1029
1030   /**
1031    * Called when a dragged item is moved from our window and the target window has done processing it.
1032    * This is when items are dragged FROM our window.
1033    */
1034   static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
1035   {
1036     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
1037     return ECORE_CALLBACK_PASS_ON;
1038   }
1039
1040   /**
1041    * Called when a dragged item is moved from our window and the target window has sent us a status.
1042    * This is when items are dragged FROM our window.
1043    */
1044   static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
1045   {
1046     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
1047     return ECORE_CALLBACK_PASS_ON;
1048   }
1049
1050   /**
1051    * Called when the client messages (i.e. the accessibility events) are received.
1052    */
1053   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
1054   {
1055 #ifndef DALI_PROFILE_UBUNTU
1056     Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
1057     EventHandler* handler( (EventHandler*)data );
1058
1059     if (clientMessageEvent->message_type == ECORE_X_ATOM_E_ILLUME_ACCESS_CONTROL)
1060     {
1061       if ( ( (unsigned int)clientMessageEvent->data.l[0] == handler->mImpl->mWindow ) && handler->mAccessibilityAdaptor )
1062       {
1063         AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1064
1065         if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_SCROLL)
1066         {
1067           // 2 finger touch & move, 2 finger flick
1068
1069           // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1070           // x : e->data.l[3]
1071           // y : e->data.l[4]
1072           TouchPoint::State state(TouchPoint::Down);
1073
1074           if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1075           {
1076             state = TouchPoint::Down; // mouse down
1077           }
1078           else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1079           {
1080             state = TouchPoint::Motion; // mouse move
1081           }
1082           else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1083           {
1084             state = TouchPoint::Up; // mouse up
1085           }
1086           else
1087           {
1088             state = TouchPoint::Interrupted; // error
1089           }
1090
1091           DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1092             "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1093             (unsigned int)clientMessageEvent->data.l[2],
1094             (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1095
1096           // Send touch event to accessibility adaptor.
1097           TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1098
1099           // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1100           accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1101         }
1102         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_MOUSE)
1103         {
1104           // 1 finger double tap and hold
1105
1106           // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1107           // x : e->data.l[3]
1108           // y : e->data.l[4]
1109           TouchPoint::State state(TouchPoint::Down);
1110
1111           if ((unsigned int)clientMessageEvent->data.l[2] == 0)
1112           {
1113             state = TouchPoint::Down; // mouse down
1114           }
1115           else if ((unsigned int)clientMessageEvent->data.l[2] == 1)
1116           {
1117             state = TouchPoint::Motion; // mouse move
1118           }
1119           else if ((unsigned int)clientMessageEvent->data.l[2] == 2)
1120           {
1121             state = TouchPoint::Up; // mouse up
1122           }
1123           else
1124           {
1125             state = TouchPoint::Interrupted; // error
1126           }
1127
1128           DALI_LOG_INFO(gClientMessageLogFilter, Debug::General,
1129             "[%s:%d] [%d] %d, %d\n", __FUNCTION__, __LINE__,
1130             (unsigned int)clientMessageEvent->data.l[2],
1131             (unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4]);
1132
1133           // Send touch event to accessibility adaptor.
1134           TouchPoint point( 0, state, (float)clientMessageEvent->data.l[3], (float)clientMessageEvent->data.l[4] );
1135
1136           // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1137           accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1138         }
1139         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_BACK)
1140         {
1141           // 2 finger circle draw, do back
1142           accessibilityAdaptor->HandleActionBackEvent();
1143         }
1144         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_NEXT)
1145         {
1146           // one finger flick down
1147           // focus next object
1148           if(accessibilityAdaptor)
1149           {
1150             accessibilityAdaptor->HandleActionNextEvent();
1151           }
1152         }
1153         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_PREV)
1154         {
1155           // one finger flick up
1156           // focus previous object
1157           if(accessibilityAdaptor)
1158           {
1159             accessibilityAdaptor->HandleActionPreviousEvent();
1160           }
1161         }
1162         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ACTIVATE)
1163         {
1164           // one finger double tap
1165           // same as one finger tap in normal mode (i.e. execute focused actor)
1166           if(accessibilityAdaptor)
1167           {
1168             accessibilityAdaptor->HandleActionActivateEvent();
1169           }
1170         }
1171         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ)
1172         {
1173           // one finger tap
1174           // focus & read an actor at ( e->data.l[2], e->data.l[3] ) position according to finger
1175           if(accessibilityAdaptor)
1176           {
1177             accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[2], (unsigned int)clientMessageEvent->data.l[3], true /* allow read again*/);
1178           }
1179         }
1180 #if defined(DALI_PROFILE_MOBILE)
1181         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_OVER)
1182         {
1183           // one finger tap & move
1184           // mouse state : e->data.l[2] (0: mouse down, 1: mouse move, 2: mouse up)
1185           // x : e->data.l[3]
1186           // y : e->data.l[4]
1187           // focus & read an actor at (x, y) position according to finger
1188           if(accessibilityAdaptor && (unsigned int)clientMessageEvent->data.l[2] == 1 /*only work for move event*/)
1189           {
1190             accessibilityAdaptor->HandleActionReadEvent((unsigned int)clientMessageEvent->data.l[3], (unsigned int)clientMessageEvent->data.l[4], false /* not allow read again*/);
1191           }
1192         }
1193 #endif
1194         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_NEXT)
1195         {
1196           // one finger flick right
1197           // focus next object
1198            if(accessibilityAdaptor)
1199           {
1200             accessibilityAdaptor->HandleActionReadNextEvent();
1201           }
1202         }
1203         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_READ_PREV)
1204         {
1205           // one finger flick left
1206           // focus previous object
1207           if(accessibilityAdaptor)
1208           {
1209             accessibilityAdaptor->HandleActionReadPreviousEvent();
1210           }
1211         }
1212         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_UP)
1213         {
1214           // double down and move (right, up)
1215           // change slider value
1216           if(accessibilityAdaptor)
1217           {
1218             accessibilityAdaptor->HandleActionUpEvent();
1219           }
1220         }
1221         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DOWN)
1222         {
1223           // double down and move (left, down)
1224           // change slider value
1225           if(accessibilityAdaptor)
1226           {
1227             accessibilityAdaptor->HandleActionDownEvent();
1228           }
1229         }
1230         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_ENABLE)
1231         {
1232            if(accessibilityAdaptor)
1233           {
1234             accessibilityAdaptor->HandleActionEnableEvent();
1235           }
1236         }
1237         else if((unsigned int)clientMessageEvent->data.l[1] == ECORE_X_ATOM_E_ILLUME_ACCESS_ACTION_DISABLE)
1238         {
1239           if(accessibilityAdaptor)
1240           {
1241             accessibilityAdaptor->HandleActionDisableEvent();
1242           }
1243         }
1244         // TODO: some more actions could be added later
1245       }
1246     }
1247     else if(clientMessageEvent->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
1248     {
1249       std::string message(clientMessageEvent->data.b);
1250       if( message == CLIPBOARD_SET_OWNER_MESSAGE)
1251       {
1252         // Claim the ownership of the SECONDARY selection.
1253         ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1254
1255         // Show the clipboard window
1256         Dali::Clipboard clipboard = Dali::Clipboard::Get();
1257         clipboard.ShowClipboard();
1258       }
1259     }
1260     else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_PREPARE )
1261     {
1262       RotationEvent rotationEvent;
1263       rotationEvent.angle      = static_cast<int>(clientMessageEvent->data.l[1]);
1264       rotationEvent.winResize  = static_cast<int>(clientMessageEvent->data.l[2]);
1265       rotationEvent.width      = static_cast<int>(clientMessageEvent->data.l[3]);
1266       rotationEvent.height     = static_cast<int>(clientMessageEvent->data.l[4]);
1267       handler->SendRotationPrepareEvent( rotationEvent );
1268     }
1269     else if( clientMessageEvent->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST )
1270     {
1271       handler->SendRotationRequestEvent();
1272     }
1273
1274 #endif // DALI_PROFILE_UBUNTU
1275     return ECORE_CALLBACK_PASS_ON;
1276   }
1277
1278
1279   /////////////////////////////////////////////////////////////////////////////////////////////////
1280   // ElDBus Accessibility Callbacks
1281   /////////////////////////////////////////////////////////////////////////////////////////////////
1282
1283 #ifdef DALI_ELDBUS_AVAILABLE
1284   // Callback for Ecore ElDBus accessibility events.
1285   static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
1286   {
1287     EventHandler* handler = static_cast< EventHandler* >( context );
1288     // Ignore any accessibility events when paused.
1289     if( handler->mPaused )
1290     {
1291       return;
1292     }
1293
1294     if ( !handler->mAccessibilityAdaptor )
1295     {
1296       DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
1297       return;
1298     }
1299
1300     AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
1301     if ( !accessibilityAdaptor )
1302     {
1303       DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
1304       return;
1305     }
1306
1307     const char *gestureName;
1308     int xS, yS, xE, yE;
1309     unsigned int state;
1310
1311     // The string defines the arg-list's respective types.
1312     if( !eldbus_message_arguments_get( message, "siiiiu", &gestureName, &xS, &yS, &xE, &yE, &state ) )
1313     {
1314       DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1315     }
1316
1317     DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %s  Args: %d,%d,%d,%d  State: %d\n", gestureName, xS, yS, xE, yE );
1318
1319     unsigned int fingers = 0;
1320     char* stringPosition = ( char* )gestureName;
1321
1322     // Check how many fingers the gesture uses.
1323     for( unsigned int i = 0; i < FingerCountStringsTotal; ++i )
1324     {
1325       unsigned int matchLength = strlen( ElDBusAccessibilityFingerCountStrings[ i ] );
1326       if( strncmp( gestureName, ElDBusAccessibilityFingerCountStrings[ i ], matchLength ) == 0 )
1327       {
1328         fingers = i + 1;
1329         stringPosition += matchLength;
1330         break;
1331       }
1332     }
1333
1334     if( fingers == 0 )
1335     {
1336       // Error: invalid gesture.
1337       return;
1338     }
1339
1340     GestureType gestureType = GESTURE_TYPE_NONE;
1341     SubGestureType subGestureType = SUB_GESTURE_TYPE_NONE;
1342     GestureDirection direction = GESTURE_DIRECTION_NONE;
1343
1344     // Check for full gesture type names first.
1345     for( unsigned int i = 0; i < FullEventTypeStringsTotal; ++i )
1346     {
1347       unsigned int matchLength = strlen( ElDBusAccessibilityFullEventTypeStrings[ i ].name );
1348       if( strncmp( stringPosition, ElDBusAccessibilityFullEventTypeStrings[ i ].name, matchLength ) == 0 )
1349       {
1350         gestureType = ElDBusAccessibilityFullEventTypeStrings[ i ].type;
1351         break;
1352       }
1353     }
1354
1355     // If we didn't find a full gesture, check for sub gesture type names.
1356     if( gestureType == GESTURE_TYPE_NONE )
1357     {
1358       // No full gesture name found, look for partial types.
1359       for( unsigned int i = 0; i < DirectionalEventTypeStringsTotal; ++i )
1360       {
1361         unsigned int matchLength = strlen( ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name );
1362         if( strncmp( stringPosition, ElDBusAccessibilityDirectionalEventTypeStrings[ i ].name, matchLength ) == 0 )
1363         {
1364           subGestureType = ElDBusAccessibilityDirectionalEventTypeStrings[ i ].type;
1365           stringPosition += matchLength;
1366         break;
1367         }
1368       }
1369
1370       if( subGestureType == SUB_GESTURE_TYPE_NONE )
1371       {
1372         // ERROR: Gesture not recognised.
1373         return;
1374       }
1375
1376       // If the gesture was a sub type, get it's respective direction.
1377       for( unsigned int i = 0; i < DirectionStringsTotal; ++i )
1378       {
1379         unsigned int matchLength = strlen( ElDBusAccessibilityDirectionStrings[ i ].name );
1380         if( strncmp( stringPosition, ElDBusAccessibilityDirectionStrings[ i ].name, matchLength ) == 0 )
1381         {
1382           direction = ElDBusAccessibilityDirectionStrings[ i ].direction;
1383           stringPosition += matchLength;
1384           break;
1385         }
1386       }
1387
1388       if( direction == GESTURE_DIRECTION_NONE )
1389       {
1390         // ERROR: Gesture not recognised.
1391         return;
1392       }
1393     }
1394
1395     // Action the detected gesture here.
1396     if( gestureType != GESTURE_TYPE_NONE )
1397     {
1398       DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d  Gesture type: %d\n", fingers, gestureType );
1399     }
1400     else
1401     {
1402       DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Fingers: %d  Gesture sub type: %d Gesture direction: %d\n",
1403         fingers, subGestureType, direction );
1404     }
1405
1406     // Create a touch point object.
1407     TouchPoint::State touchPointState( TouchPoint::Down );
1408     if ( state == 0 )
1409     {
1410       touchPointState = TouchPoint::Down; // Mouse down.
1411     }
1412     else if ( state == 1 )
1413     {
1414       touchPointState = TouchPoint::Motion; // Mouse move.
1415     }
1416     else if ( state == 2 )
1417     {
1418       touchPointState = TouchPoint::Up; // Mouse up.
1419     }
1420     else
1421     {
1422       touchPointState = TouchPoint::Interrupted; // Error.
1423     }
1424
1425     // Send touch event to accessibility adaptor.
1426     TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1427
1428     // Perform actions based on received gestures.
1429     // Note: This is seperated from the reading so we can (in future)
1430     // have other input readers without changing the below code.
1431     switch( fingers )
1432     {
1433       case 1:
1434       {
1435         if( gestureType == GESTURE_TYPE_SINGLE_TAP || ( gestureType == GESTURE_TYPE_HOVER && touchPointState == TouchPoint::Motion ) )
1436         {
1437           // Focus, read out.
1438           accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1439         }
1440         else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1441         {
1442           if( false ) // TODO: how to detect double tap + hold?
1443           {
1444             // Move or drag icon / view more options for selected items.
1445             // accessibilityAdaptor->HandleActionTouchEvent( point, GetCurrentMilliSeconds() );
1446           }
1447           else
1448           {
1449             // Activate selected item / active edit mode.
1450             accessibilityAdaptor->HandleActionActivateEvent();
1451           }
1452         }
1453         else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1454         {
1455           // Zoom
1456           accessibilityAdaptor->HandleActionZoomEvent();
1457         }
1458         else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1459         {
1460           if( direction == GESTURE_DIRECTION_LEFT )
1461           {
1462             // Move to previous item.
1463             accessibilityAdaptor->HandleActionReadPreviousEvent();
1464           }
1465           else if( direction == GESTURE_DIRECTION_RIGHT )
1466           {
1467             // Move to next item.
1468             accessibilityAdaptor->HandleActionReadNextEvent();
1469           }
1470           else if( direction == GESTURE_DIRECTION_UP )
1471           {
1472             // Move to next item.
1473             accessibilityAdaptor->HandleActionPreviousEvent();
1474           }
1475           else if( direction == GESTURE_DIRECTION_DOWN )
1476           {
1477             // Move to next item.
1478             accessibilityAdaptor->HandleActionNextEvent();
1479           }
1480           else if( direction == GESTURE_DIRECTION_LEFT_RETURN )
1481           {
1482             // Scroll up to the previous page
1483             accessibilityAdaptor->HandleActionPageUpEvent();
1484           }
1485           else if( direction == GESTURE_DIRECTION_RIGHT_RETURN )
1486           {
1487             // Scroll down to the next page
1488             accessibilityAdaptor->HandleActionPageDownEvent();
1489           }
1490           else if( direction == GESTURE_DIRECTION_UP_RETURN )
1491           {
1492             // Move to the first item on screen
1493             accessibilityAdaptor->HandleActionMoveToFirstEvent();
1494           }
1495           else if( direction == GESTURE_DIRECTION_DOWN_RETURN )
1496           {
1497             // Move to the last item on screen
1498             accessibilityAdaptor->HandleActionMoveToLastEvent();
1499           }
1500         }
1501         break;
1502       }
1503
1504       case 2:
1505       {
1506         if( gestureType == GESTURE_TYPE_HOVER )
1507         {
1508           // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1509           accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1510         }
1511         else if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1512         {
1513           // Pause/Resume current speech
1514           accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1515         }
1516         else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1517         {
1518           // Start/Stop current action
1519           accessibilityAdaptor->HandleActionStartStopEvent();
1520         }
1521         else if( gestureType == GESTURE_TYPE_TRIPLE_TAP )
1522         {
1523           // Read information from indicator
1524           accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1525         }
1526         else if( subGestureType == SUB_GESTURE_TYPE_FLICK )
1527         {
1528           if( direction == GESTURE_DIRECTION_LEFT )
1529           {
1530             // Scroll left to the previous page
1531             accessibilityAdaptor->HandleActionPageLeftEvent();
1532           }
1533           else if( direction == GESTURE_DIRECTION_RIGHT )
1534           {
1535             // Scroll right to the next page
1536             accessibilityAdaptor->HandleActionPageRightEvent();
1537           }
1538           else if( direction == GESTURE_DIRECTION_UP )
1539           {
1540             // Scroll up the list.
1541             accessibilityAdaptor->HandleActionScrollUpEvent();
1542           }
1543           else if( direction == GESTURE_DIRECTION_DOWN )
1544           {
1545             // Scroll down the list.
1546             accessibilityAdaptor->HandleActionScrollDownEvent();
1547           }
1548         }
1549         break;
1550       }
1551
1552       case 3:
1553       {
1554         if( gestureType == GESTURE_TYPE_SINGLE_TAP )
1555         {
1556           // Read from top item on screen continuously.
1557           accessibilityAdaptor->HandleActionReadFromTopEvent();
1558         }
1559         else if( gestureType == GESTURE_TYPE_DOUBLE_TAP )
1560         {
1561           // Read from next item continuously.
1562           accessibilityAdaptor->HandleActionReadFromNextEvent();
1563         }
1564         break;
1565       }
1566     }
1567   }
1568
1569   // Callback for to set up Ecore ElDBus for accessibility callbacks.
1570   static void EcoreElDBusInitialisation( void *handle, const Eldbus_Message *message, Eldbus_Pending *pending EINA_UNUSED )
1571   {
1572     Eldbus_Object *object;
1573     Eldbus_Proxy *manager;
1574     const char *a11yBusAddress = NULL;
1575     EventHandler* handler = static_cast< EventHandler* >( handle );
1576
1577     // The string defines the arg-list's respective types.
1578     if( !eldbus_message_arguments_get( message, "s", &a11yBusAddress ) )
1579     {
1580       DALI_LOG_ERROR( "EcoreElDBusInitialisation: Error getting arguments\n" );
1581     }
1582
1583     DALI_LOG_INFO( gImfLogging, Debug::General, "Ecore ElDBus Accessibility address: %s\n", a11yBusAddress );
1584
1585     handler->mImpl->mA11yConnection = eldbus_address_connection_get( a11yBusAddress );
1586
1587     object = eldbus_object_get( handler->mImpl->mA11yConnection, BUS, PATH );
1588     manager = eldbus_proxy_get( object, INTERFACE );
1589
1590     // Pass the callback data through to the signal handler.
1591     eldbus_proxy_signal_handler_add( manager, SIGNAL, OnEcoreElDBusAccessibilityNotification, handle );
1592   }
1593 #endif // DALI_ELDBUS_AVAILABLE
1594
1595   /**
1596    * Called when the source window notifies us the content in clipboard is selected.
1597    */
1598   static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1599   {
1600     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1601     Ecore_X_Event_Selection_Clear* selectionClearEvent( (Ecore_X_Event_Selection_Clear*) event );
1602     EventHandler* handler( (EventHandler*)data );
1603
1604     if ( selectionClearEvent->win == handler->mImpl->mWindow )
1605     {
1606       if ( selectionClearEvent->selection == ECORE_X_SELECTION_SECONDARY )
1607       {
1608         // Request to get the content from Ecore.
1609         ecore_x_selection_secondary_request(selectionClearEvent->win, ECORE_X_SELECTION_TARGET_TEXT);
1610       }
1611     }
1612     return ECORE_CALLBACK_PASS_ON;
1613   }
1614
1615   /**
1616    * Called when the source window sends us about the selected content.
1617    * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1618    */
1619   static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1620   {
1621     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1622
1623     Ecore_X_Event_Selection_Notify* selectionNotifyEvent( (Ecore_X_Event_Selection_Notify*) event );
1624     EventHandler* handler( (EventHandler*)data );
1625
1626     if ( selectionNotifyEvent->win == handler->mImpl->mWindow )
1627     {
1628       Ecore_X_Selection_Data* selectionData( (Ecore_X_Selection_Data*) selectionNotifyEvent->data );
1629       if ( selectionData->data )
1630       {
1631         if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_XDND )
1632         {
1633           DragAndDropDetectorPtr dndDetector( handler->mDragAndDropDetector );
1634
1635           // We have got the content that is to be dropped, inform the DndListener (if we have one).
1636           if ( dndDetector )
1637           {
1638             std::string content( (char*) selectionData->data, selectionData->length );
1639             dndDetector->SetContent( content );
1640
1641             DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1642             DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1643             DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1644             DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1645           }
1646         }
1647         else if ( selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY )
1648         {
1649           // We have got the selected content, inform the clipboard event listener (if we have one).
1650           if ( handler->mClipboardEventNotifier )
1651           {
1652             ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1653             std::string content( (char*) selectionData->data, selectionData->length );
1654             clipboardEventNotifier.SetContent( content );
1655             clipboardEventNotifier.EmitContentSelectedSignal();
1656           }
1657
1658           // Claim the ownership of the SECONDARY selection.
1659           ecore_x_selection_secondary_set(handler->mImpl->mWindow, "", 1);
1660
1661           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d):\n" , selectionData->length );
1662           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1663           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
1664           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
1665         }
1666       }
1667     }
1668     return ECORE_CALLBACK_PASS_ON;
1669   }
1670
1671
1672 #ifndef DALI_PROFILE_UBUNTU
1673   /////////////////////////////////////////////////////////////////////////////////////////////////
1674   // Font Callbacks
1675   /////////////////////////////////////////////////////////////////////////////////////////////////
1676   /**
1677    * Called when a font name is changed.
1678    */
1679   static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1680   {
1681     EventHandler* handler = static_cast<EventHandler*>( data );
1682     handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1683   }
1684
1685   /**
1686    * Called when a font size is changed.
1687    */
1688   static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1689   {
1690     DALI_LOG_INFO(gTouchEventLogFilter, Debug::Verbose, "VconfNotifyFontSizeChanged\n" );
1691     EventHandler* handler = static_cast<EventHandler*>( data );
1692     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1693   }
1694 #endif // DALI_PROFILE_UBUNTU
1695
1696   // Data
1697   EventHandler* mHandler;
1698   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1699   Ecore_X_Window mWindow;
1700   int mXiDeviceId;
1701
1702 #ifdef DALI_ELDBUS_AVAILABLE
1703   Eldbus_Connection* mSessionConnection;
1704   Eldbus_Connection* mA11yConnection;
1705 #endif
1706 };
1707
1708 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1709 : mCoreEventInterface( coreEventInterface ),
1710   mGestureManager( gestureManager ),
1711   mStyleMonitor( StyleMonitor::Get() ),
1712   mDamageObserver( damageObserver ),
1713   mRotationObserver( NULL ),
1714   mDragAndDropDetector( dndDetector ),
1715   mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1716   mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1717   mClipboard( Clipboard::Get() ),
1718   mImpl( NULL ),
1719   mPaused( false )
1720 {
1721   Ecore_X_Window window = 0;
1722
1723   // this code only works with the EcoreX11 RenderSurface so need to downcast
1724   ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1725   if( ecoreSurface )
1726   {
1727     // enable multi touch
1728     window = ecoreSurface->GetXWindow();
1729   }
1730
1731   mImpl = new Impl(this, window);
1732 }
1733
1734 EventHandler::~EventHandler()
1735 {
1736   delete mImpl;
1737
1738   mGestureManager.Stop();
1739 }
1740
1741 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1742 {
1743   if(timeStamp < 1)
1744   {
1745     timeStamp = GetCurrentMilliSeconds();
1746   }
1747
1748   Integration::TouchEvent touchEvent;
1749   Integration::HoverEvent hoverEvent;
1750   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1751   if(type != Integration::TouchEventCombiner::DispatchNone )
1752   {
1753     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);
1754
1755     // First the touch and/or hover event & related gesture events are queued
1756     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1757     {
1758       mCoreEventInterface.QueueCoreEvent( touchEvent );
1759       mGestureManager.SendEvent(touchEvent);
1760     }
1761
1762     if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1763     {
1764       mCoreEventInterface.QueueCoreEvent( hoverEvent );
1765     }
1766
1767     // Next the events are processed with a single call into Core
1768     mCoreEventInterface.ProcessCoreEvents();
1769   }
1770 }
1771
1772 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1773 {
1774   Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1775   if ( physicalKeyboard )
1776   {
1777     if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1778     {
1779       GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1780     }
1781   }
1782
1783   // Send to KeyEvent Core.
1784   mCoreEventInterface.QueueCoreEvent( keyEvent );
1785   mCoreEventInterface.ProcessCoreEvents();
1786 }
1787
1788 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1789 {
1790   // Create WheelEvent and send to Core.
1791   Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1792   mCoreEventInterface.QueueCoreEvent( event );
1793   mCoreEventInterface.ProcessCoreEvents();
1794 }
1795
1796 void EventHandler::SendEvent( StyleChange::Type styleChange )
1797 {
1798   DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1799   GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1800 }
1801
1802 void EventHandler::SendEvent( const DamageArea& area )
1803 {
1804   mDamageObserver.OnDamaged( area );
1805 }
1806
1807 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1808 {
1809   if( mRotationObserver != NULL )
1810   {
1811     mRotationObserver->OnRotationPrepare( event );
1812   }
1813 }
1814
1815 void EventHandler::SendRotationRequestEvent( )
1816 {
1817   if( mRotationObserver != NULL )
1818   {
1819     mRotationObserver->OnRotationRequest( );
1820   }
1821 }
1822
1823 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1824 {
1825   Integration::Point convertedPoint( point );
1826
1827   SendEvent(convertedPoint, timeStamp);
1828 }
1829
1830 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1831 {
1832   SendWheelEvent( wheelEvent );
1833 }
1834
1835 void EventHandler::FeedKeyEvent( KeyEvent& event )
1836 {
1837   Integration::KeyEvent convertedEvent( event );
1838   SendEvent( convertedEvent );
1839 }
1840
1841 void EventHandler::FeedEvent( Integration::Event& event )
1842 {
1843   mCoreEventInterface.QueueCoreEvent( event );
1844   mCoreEventInterface.ProcessCoreEvents();
1845 }
1846
1847 void EventHandler::Reset()
1848 {
1849   mCombiner.Reset();
1850
1851   // Any touch listeners should be told of the interruption.
1852   Integration::TouchEvent event;
1853   Integration::Point point;
1854   point.SetState( PointState::INTERRUPTED );
1855   event.AddPoint( point );
1856
1857   // First the touch event & related gesture events are queued
1858   mCoreEventInterface.QueueCoreEvent( event );
1859   mGestureManager.SendEvent( event );
1860
1861   // Next the events are processed with a single call into Core
1862   mCoreEventInterface.ProcessCoreEvents();
1863 }
1864
1865 void EventHandler::Pause()
1866 {
1867   mPaused = true;
1868   Reset();
1869 }
1870
1871 void EventHandler::Resume()
1872 {
1873   mPaused = false;
1874   Reset();
1875 }
1876
1877 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1878 {
1879   mDragAndDropDetector = detector;
1880 }
1881
1882 void EventHandler::SetRotationObserver( RotationObserver* observer )
1883 {
1884   mRotationObserver = observer;
1885 }
1886
1887 } // namespace Adaptor
1888
1889 } // namespace Internal
1890
1891 } // namespace Dali
1892
1893 #pragma GCC diagnostic pop