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