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