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