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