Merge "Added handler for ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / event-handler-ecore-wl.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <events/event-handler.h>
20
21 // EXTERNAL INCLUDES
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
25 #include <Ecore.h>
26 #include <Ecore_Input.h>
27 #include <ecore-wl-render-surface.h>
28 #include <cstring>
29
30 #include <sys/time.h>
31
32 #ifndef DALI_PROFILE_UBUNTU
33 #include <vconf.h>
34 #include <vconf-keys.h>
35 #endif // DALI_PROFILE_UBUNTU
36
37 #ifdef DALI_ELDBUS_AVAILABLE
38 #include <Eldbus.h>
39 #endif // DALI_ELDBUS_AVAILABLE
40
41 #include <dali/public-api/common/vector-wrapper.h>
42 #include <dali/public-api/events/touch-point.h>
43 #include <dali/public-api/events/key-event.h>
44 #include <dali/public-api/events/wheel-event.h>
45 #include <dali/integration-api/debug.h>
46 #include <dali/integration-api/events/key-event-integ.h>
47 #include <dali/integration-api/events/touch-event-integ.h>
48 #include <dali/integration-api/events/hover-event-integ.h>
49 #include <dali/integration-api/events/wheel-event-integ.h>
50 #include <dali/devel-api/events/key-event-devel.h>
51
52 // INTERNAL INCLUDES
53 #include <events/gesture-manager.h>
54 #include <window-render-surface.h>
55 #include <clipboard-impl.h>
56 #include <key-impl.h>
57 #include <physical-keyboard-impl.h>
58 #include <style-monitor-impl.h>
59 #include <base/core-event-interface.h>
60 #include <virtual-keyboard.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* gDragAndDropLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_DND");
76 Integration::Log::Filter* gImfLogging  = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_IMF");
77 Integration::Log::Filter* gSelectionEventLogFilter = Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_ADAPTOR_EVENTS_SELECTION");
78 } // unnamed namespace
79 #endif
80
81
82 namespace
83 {
84
85 // DBUS accessibility
86 const char* BUS = "org.enlightenment.wm-screen-reader";
87 const char* INTERFACE = "org.tizen.GestureNavigation";
88 const char* PATH = "/org/tizen/GestureNavigation";
89
90 const unsigned int PRIMARY_TOUCH_BUTTON_ID( 1 );
91
92 const unsigned int BYTES_PER_CHARACTER_FOR_ATTRIBUTES = 3;
93
94 /**
95  * Ecore_Event_Modifier enums in Ecore_Input.h do not match Ecore_IMF_Keyboard_Modifiers in Ecore_IMF.h.
96  * This function converts from Ecore_Event_Modifier to Ecore_IMF_Keyboard_Modifiers enums.
97  * @param[in] ecoreModifier the Ecore_Event_Modifier input.
98  * @return the Ecore_IMF_Keyboard_Modifiers output.
99  */
100 Ecore_IMF_Keyboard_Modifiers EcoreInputModifierToEcoreIMFModifier(unsigned int ecoreModifier)
101 {
102    int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE );  // If no other matches returns NONE.
103
104
105    if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT )  // enums from ecore_input/Ecore_Input.h
106    {
107      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;  // enums from ecore_imf/ecore_imf.h
108    }
109
110    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )
111    {
112      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;
113    }
114
115    if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )
116    {
117      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;
118    }
119
120    if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )
121    {
122      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;
123    }
124
125    if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )
126    {
127      modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;
128    }
129
130    return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );
131 }
132
133
134 // Copied from x server
135 static unsigned int GetCurrentMilliSeconds(void)
136 {
137   struct timeval tv;
138
139   struct timespec tp;
140   static clockid_t clockid;
141
142   if (!clockid)
143   {
144 #ifdef CLOCK_MONOTONIC_COARSE
145     if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
146       (tp.tv_nsec / 1000) <= 1000 && clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
147     {
148       clockid = CLOCK_MONOTONIC_COARSE;
149     }
150     else
151 #endif
152     if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
153     {
154       clockid = CLOCK_MONOTONIC;
155     }
156     else
157     {
158       clockid = ~0L;
159     }
160   }
161   if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
162   {
163     return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
164   }
165
166   gettimeofday(&tv, NULL);
167   return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
168 }
169
170 #ifndef DALI_PROFILE_UBUNTU
171 const char * DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE = "db/setting/accessibility/font_name";  // It will be update at vconf-key.h and replaced.
172 #endif // DALI_PROFILE_UBUNTU
173
174 /**
175  * Get the device name from the provided ecore key event
176  */
177 void GetDeviceName(  Ecore_Event_Key* keyEvent, std::string& result )
178 {
179   const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
180
181   if ( ecoreDeviceName )
182   {
183     result = ecoreDeviceName;
184   }
185 }
186
187 /**
188  * Get the device class from the provided ecore key event
189  */
190 void GetDeviceClass(  Ecore_Event_Key* keyEvent, DevelKeyEvent::DeviceClass::Type& deviceClass )
191 {
192   Ecore_Device_Class ecoreDeviceClass = ecore_device_class_get( keyEvent->dev );
193
194   switch( ecoreDeviceClass )
195   {
196     case ECORE_DEVICE_CLASS_SEAT:
197     {
198       deviceClass = DevelKeyEvent::DeviceClass::USER;
199       break;
200     }
201     case ECORE_DEVICE_CLASS_KEYBOARD:
202     {
203       deviceClass = DevelKeyEvent::DeviceClass::KEYBOARD;
204       break;
205     }
206     case ECORE_DEVICE_CLASS_MOUSE:
207     {
208       deviceClass = DevelKeyEvent::DeviceClass::MOUSE;
209       break;
210     }
211     case ECORE_DEVICE_CLASS_TOUCH:
212     {
213       deviceClass = DevelKeyEvent::DeviceClass::TOUCH;
214       break;
215     }
216     case ECORE_DEVICE_CLASS_PEN:
217     {
218       deviceClass = DevelKeyEvent::DeviceClass::PEN;
219       break;
220     }
221     case ECORE_DEVICE_CLASS_POINTER:
222     {
223       deviceClass = DevelKeyEvent::DeviceClass::POINTER;
224       break;
225     }
226     case ECORE_DEVICE_CLASS_GAMEPAD:
227     {
228       deviceClass = DevelKeyEvent::DeviceClass::GAMEPAD;
229       break;
230     }
231     default:
232     {
233       deviceClass = DevelKeyEvent::DeviceClass::NONE;
234       break;
235     }
236   }
237 }
238
239 } // unnamed namespace
240
241 // Impl to hide EFL implementation.
242 struct EventHandler::Impl
243 {
244   // Construction & Destruction
245
246   /**
247    * Constructor
248    */
249   Impl( EventHandler* handler, Ecore_Wl_Window* window )
250   : mHandler( handler ),
251     mEcoreEventHandler(),
252     mWindow( window )
253 #ifdef DALI_ELDBUS_AVAILABLE
254   , mSystemConnection( NULL )
255 #endif // DALI_ELDBUS_AVAILABLE
256   {
257     // Only register for touch and key events if we have a window
258     if ( window != 0 )
259     {
260       // Register Touch events
261       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,   EcoreEventMouseButtonDown,   handler ) );
262       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,     EcoreEventMouseButtonUp,     handler ) );
263       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,          EcoreEventMouseButtonMove,   handler ) );
264       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_OUT,           EcoreEventMouseButtonUp,     handler ) ); // process mouse out event like up event
265       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, handler ) );
266
267       // Register Mouse wheel events
268       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,        EcoreEventMouseWheel,      handler ) );
269
270       // Register Focus events
271       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN,  EcoreEventWindowFocusIn,   handler ) );
272       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut,  handler ) );
273
274       // Register Key events
275       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,           EcoreEventKeyDown,         handler ) );
276       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_KEY_UP,             EcoreEventKeyUp,           handler ) );
277
278       // Register Selection event - clipboard selection
279       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, handler ) );
280       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, handler ) );
281
282       // Register Rotate event
283       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, handler) );
284
285       // Register Detent event
286       mEcoreEventHandler.push_back( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE, EcoreEventDetent, handler) );
287
288 #ifndef DALI_PROFILE_UBUNTU
289       // Register Vconf notify - font name and size
290       vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged, handler );
291       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, handler );
292 #endif // DALI_PROFILE_UBUNTU
293
294 #ifdef DALI_ELDBUS_AVAILABLE
295       // Initialize ElDBus.
296       DALI_LOG_INFO( gImfLogging, Debug::General, "Starting DBus Initialization\n" );
297
298       // Pass in handler.
299       EcoreElDBusInitialisation( handler );
300
301       DALI_LOG_INFO( gImfLogging, Debug::General, "Finished DBus Initialization\n" );
302 #endif // DALI_ELDBUS_AVAILABLE
303     }
304   }
305
306   /**
307    * Destructor
308    */
309   ~Impl()
310   {
311 #ifndef DALI_PROFILE_UBUNTU
312     vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
313     vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontNameChanged );
314 #endif // DALI_PROFILE_UBUNTU
315
316     for( std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandler.begin(), endIter = mEcoreEventHandler.end(); iter != endIter; ++iter )
317     {
318       ecore_event_handler_del( *iter );
319     }
320
321 #ifdef DALI_ELDBUS_AVAILABLE
322     // Close down ElDBus connections.
323     if( mSystemConnection )
324     {
325       eldbus_connection_unref( mSystemConnection );
326     }
327 #endif // DALI_ELDBUS_AVAILABLE
328   }
329
330   // Static methods
331
332   /////////////////////////////////////////////////////////////////////////////////////////////////
333   // Touch Callbacks
334   /////////////////////////////////////////////////////////////////////////////////////////////////
335
336   /**
337    * Called when a touch down is received.
338    */
339   static Eina_Bool EcoreEventMouseButtonDown( void* data, int type, void* event )
340   {
341     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
342     EventHandler* handler( (EventHandler*)data );
343
344     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
345     {
346       PointState::Type state ( PointState::DOWN );
347
348       // Check if the buttons field is set and ensure it's the primary touch button.
349       // If this event was triggered by buttons other than the primary button (used for touch), then
350       // just send an interrupted event to Core.
351       if ( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
352       {
353         state = PointState::INTERRUPTED;
354       }
355
356       Integration::Point point;
357       point.SetDeviceId( touchEvent->multi.device );
358       point.SetState( state );
359       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
360       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
361       point.SetPressure( touchEvent->multi.pressure );
362       point.SetAngle( Degree( touchEvent->multi.angle ) );
363       handler->SendEvent( point, touchEvent->timestamp );
364     }
365
366     return ECORE_CALLBACK_PASS_ON;
367   }
368
369   /**
370    * Called when a touch up is received.
371    */
372   static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
373   {
374     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
375     EventHandler* handler( (EventHandler*)data );
376
377     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
378     {
379       Integration::Point point;
380       point.SetDeviceId( touchEvent->multi.device );
381       point.SetState( PointState::UP );
382       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
383       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
384       point.SetPressure( touchEvent->multi.pressure );
385       point.SetAngle( Degree( touchEvent->multi.angle ) );
386       handler->SendEvent( point, touchEvent->timestamp );
387     }
388
389     return ECORE_CALLBACK_PASS_ON;
390   }
391
392   /**
393    * Called when a touch motion is received.
394    */
395   static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
396   {
397     Ecore_Event_Mouse_Move *touchEvent( (Ecore_Event_Mouse_Move*)event );
398     EventHandler* handler( (EventHandler*)data );
399
400     if ( touchEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
401     {
402       Integration::Point point;
403       point.SetDeviceId( touchEvent->multi.device );
404       point.SetState( PointState::MOTION );
405       point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
406       point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
407       point.SetPressure( touchEvent->multi.pressure );
408       point.SetAngle( Degree( touchEvent->multi.angle ) );
409       handler->SendEvent( point, touchEvent->timestamp );
410     }
411
412     return ECORE_CALLBACK_PASS_ON;
413   }
414
415   /**
416    * Called when a touch is canceled.
417    */
418   static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
419   {
420     Ecore_Event_Mouse_Button *touchEvent( (Ecore_Event_Mouse_Button*)event );
421     EventHandler* handler( (EventHandler*)data );
422
423     if( touchEvent->window == (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
424     {
425       Integration::Point point;
426       point.SetDeviceId( touchEvent->multi.device );
427       point.SetState( PointState::INTERRUPTED );
428       point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
429       handler->SendEvent( point, touchEvent->timestamp );
430
431       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventMouseButtonCancel\n" );
432     }
433
434     return ECORE_CALLBACK_PASS_ON;
435   }
436
437   /**
438    * Called when a mouse wheel is received.
439    */
440   static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
441   {
442     Ecore_Event_Mouse_Wheel *mouseWheelEvent( (Ecore_Event_Mouse_Wheel*)event );
443
444     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);
445
446     EventHandler* handler( (EventHandler*)data );
447     if ( mouseWheelEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
448     {
449       WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp );
450       handler->SendWheelEvent( wheelEvent );
451     }
452     return ECORE_CALLBACK_PASS_ON;
453   }
454
455   /////////////////////////////////////////////////////////////////////////////////////////////////
456   // Key Callbacks
457   /////////////////////////////////////////////////////////////////////////////////////////////////
458
459   /**
460    * Called when a key down is received.
461    */
462   static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
463   {
464     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyDown \n" );
465
466     EventHandler* handler( (EventHandler*)data );
467     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
468     bool eventHandled( false );
469
470     // If a device key then skip ecore_imf_context_filter_event.
471     if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
472     {
473       Ecore_IMF_Context* imfContext = NULL;
474       Dali::ImfManager imfManager( ImfManager::Get() );
475       if ( imfManager )
476       {
477         imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
478       }
479
480       if ( imfContext )
481       {
482         // We're consuming key down event so we have to pass to IMF so that it can parse it as well.
483         Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;
484         ecoreKeyDownEvent.keyname   = keyEvent->keyname;
485         ecoreKeyDownEvent.key       = keyEvent->key;
486         ecoreKeyDownEvent.string    = keyEvent->string;
487         ecoreKeyDownEvent.compose   = keyEvent->compose;
488         ecoreKeyDownEvent.timestamp = keyEvent->timestamp;
489         ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
490         ecoreKeyDownEvent.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
491         ecoreKeyDownEvent.dev_name  = "";
492         ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
493         ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
494
495         std::string checkDevice;
496         GetDeviceName( keyEvent, checkDevice );
497
498         // If the device is IME and the focused key is the direction keys, then we should send a key event to move a key cursor.
499         if( ( checkDevice == "ime" ) && ( ( !strncmp( keyEvent->keyname, "Left",  4 ) ) ||
500                                           ( !strncmp( keyEvent->keyname, "Right", 5 ) ) ||
501                                           ( !strncmp( keyEvent->keyname, "Up",    2 ) ) ||
502                                           ( !strncmp( keyEvent->keyname, "Down",  4 ) ) ) )
503         {
504           eventHandled = 0;
505         }
506         else
507         {
508           eventHandled = ecore_imf_context_filter_event( imfContext,
509                                                          ECORE_IMF_EVENT_KEY_DOWN,
510                                                          (Ecore_IMF_Event *) &ecoreKeyDownEvent );
511         }
512
513         // If the event has not been handled by IMF then check if we should reset our IMF context
514         if( !eventHandled )
515         {
516           if ( !strcmp( keyEvent->keyname, "Escape"   ) ||
517                !strcmp( keyEvent->keyname, "Return"   ) ||
518                !strcmp( keyEvent->keyname, "KP_Enter" ) )
519           {
520             ecore_imf_context_reset( imfContext );
521           }
522         }
523       }
524     }
525
526     // If the event wasn't handled then we should send a key event.
527     if ( !eventHandled )
528     {
529       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
530       {
531         std::string keyName( keyEvent->keyname );
532         std::string keyString( "" );
533         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
534         keyCode = (keyCode == -1) ? 0 : keyCode;
535         int modifier( keyEvent->modifiers );
536         unsigned long time = keyEvent->timestamp;
537         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
538           keyCode = atoi(keyEvent->keyname + 8);
539
540         // Ensure key event string is not NULL as keys like SHIFT have a null string.
541         if ( keyEvent->string )
542         {
543           keyString = keyEvent->string;
544         }
545
546         std::string deviceName;
547         DevelKeyEvent::DeviceClass::Type deviceClass;
548
549         GetDeviceName( keyEvent, deviceName );
550         GetDeviceClass( keyEvent, deviceClass );
551
552         DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
553
554         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass );
555         handler->SendEvent( keyEvent );
556       }
557     }
558
559     return ECORE_CALLBACK_PASS_ON;
560   }
561
562   /**
563    * Called when a key up is received.
564    */
565   static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
566   {
567     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
568
569     EventHandler* handler( (EventHandler*)data );
570     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
571     bool eventHandled( false );
572
573     // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
574     if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
575     {
576       Ecore_IMF_Context* imfContext = NULL;
577       Dali::ImfManager imfManager( ImfManager::Get() );
578       if ( imfManager )
579       {
580         imfContext = ImfManager::GetImplementation( imfManager ).GetContext();
581       }
582
583       if ( imfContext )
584       {
585         // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
586         Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
587         ecoreKeyUpEvent.keyname   = keyEvent->keyname;
588         ecoreKeyUpEvent.key       = keyEvent->key;
589         ecoreKeyUpEvent.string    = keyEvent->string;
590         ecoreKeyUpEvent.compose   = keyEvent->compose;
591         ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
592         ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
593         ecoreKeyUpEvent.locks     = (Ecore_IMF_Keyboard_Locks) ECORE_IMF_KEYBOARD_LOCK_NONE;
594         ecoreKeyUpEvent.dev_name  = "";
595         ecoreKeyUpEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;
596         ecoreKeyUpEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;
597
598         eventHandled = ecore_imf_context_filter_event( imfContext,
599                                                        ECORE_IMF_EVENT_KEY_UP,
600                                                        (Ecore_IMF_Event *) &ecoreKeyUpEvent );
601       }
602     }
603
604     // If the event wasn't handled then we should send a key event.
605     if ( !eventHandled )
606     {
607       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
608       {
609         std::string keyName( keyEvent->keyname );
610         std::string keyString( "" );
611         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
612         keyCode = (keyCode == -1) ? 0 : keyCode;
613         int modifier( keyEvent->modifiers );
614         unsigned long time = keyEvent->timestamp;
615         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
616           keyCode = atoi(keyEvent->keyname + 8);
617
618         // Ensure key event string is not NULL as keys like SHIFT have a null string.
619         if ( keyEvent->string )
620         {
621           keyString = keyEvent->string;
622         }
623
624         std::string deviceName;
625         DevelKeyEvent::DeviceClass::Type deviceClass;
626
627         GetDeviceName( keyEvent, deviceName );
628         GetDeviceClass( keyEvent, deviceClass );
629
630         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass );
631         handler->SendEvent( keyEvent );
632       }
633     }
634
635     return ECORE_CALLBACK_PASS_ON;
636   }
637
638   /////////////////////////////////////////////////////////////////////////////////////////////////
639   // Window Callbacks
640   /////////////////////////////////////////////////////////////////////////////////////////////////
641
642   /**
643    * Called when the window gains focus.
644    */
645   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
646   {
647     Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
648     EventHandler* handler( (EventHandler*)data );
649
650     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
651
652     // If the window gains focus and we hid the keyboard then show it again.
653     if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
654     {
655       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
656
657       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
658       {
659         Dali::ImfManager imfManager( ImfManager::Get() );
660         if ( imfManager )
661         {
662           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
663           if( imfManagerImpl.RestoreAfterFocusLost() )
664           {
665             imfManagerImpl.Activate();
666           }
667         }
668       }
669       Dali::Clipboard clipboard = Clipboard::Get();
670       clipboard.HideClipboard();
671     }
672
673     return ECORE_CALLBACK_PASS_ON;
674   }
675
676   /**
677    * Called when the window loses focus.
678    */
679   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
680   {
681     Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
682     EventHandler* handler( (EventHandler*)data );
683
684     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
685
686     // If the window loses focus then hide the keyboard.
687     if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
688     {
689       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
690       {
691         Dali::ImfManager imfManager( ImfManager::Get() );
692         if ( imfManager )
693         {
694           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
695           if( imfManagerImpl.RestoreAfterFocusLost() )
696           {
697             imfManagerImpl.Deactivate();
698           }
699         }
700       }
701
702       // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
703       Dali::Clipboard clipboard = Clipboard::Get();
704       if ( clipboard )
705       {
706         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
707         clipBoardImpl.HideClipboard(true);
708       }
709     }
710
711     return ECORE_CALLBACK_PASS_ON;
712   }
713
714   /**
715    * Called when the window is damaged.
716    */
717   static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
718   {
719     return ECORE_CALLBACK_PASS_ON;
720   }
721
722   /**
723    * Called when the window properties are changed.
724    * We are only interested in the font change.
725    */
726
727
728   /////////////////////////////////////////////////////////////////////////////////////////////////
729   // Drag & Drop Callbacks
730   /////////////////////////////////////////////////////////////////////////////////////////////////
731
732   /**
733    * Called when a dragged item enters our window's bounds.
734    * This is when items are dragged INTO our window.
735    */
736   static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
737   {
738     DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
739
740     return ECORE_CALLBACK_PASS_ON;
741   }
742
743   /**
744    * Called when a dragged item is moved within our window.
745    * This is when items are dragged INTO our window.
746    */
747   static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
748   {
749     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
750
751     return ECORE_CALLBACK_PASS_ON;
752   }
753
754   /**
755    * Called when a dragged item leaves our window's bounds.
756    * This is when items are dragged INTO our window.
757    */
758   static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
759   {
760     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
761
762     return ECORE_CALLBACK_PASS_ON;
763   }
764
765   /**
766    * Called when the dragged item is dropped within our window's bounds.
767    * This is when items are dragged INTO our window.
768    */
769   static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
770   {
771     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
772
773     return ECORE_CALLBACK_PASS_ON;
774   }
775
776   /**
777    * Called when a dragged item is moved from our window and the target window has done processing it.
778    * This is when items are dragged FROM our window.
779    */
780   static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
781   {
782     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
783     return ECORE_CALLBACK_PASS_ON;
784   }
785
786   /**
787    * Called when a dragged item is moved from our window and the target window has sent us a status.
788    * This is when items are dragged FROM our window.
789    */
790   static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
791   {
792     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
793     return ECORE_CALLBACK_PASS_ON;
794   }
795
796   /**
797    * Called when the client messages (i.e. the accessibility events) are received.
798    */
799   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
800   {
801     return ECORE_CALLBACK_PASS_ON;
802   }
803
804
805   /////////////////////////////////////////////////////////////////////////////////////////////////
806   // ElDBus Accessibility Callbacks
807   /////////////////////////////////////////////////////////////////////////////////////////////////
808
809 #ifdef DALI_ELDBUS_AVAILABLE
810   // Callback for Ecore ElDBus accessibility events.
811   static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
812   {
813     EventHandler* handler = static_cast< EventHandler* >( context );
814     // Ignore any accessibility events when paused.
815     if( handler->mPaused )
816     {
817       return;
818     }
819
820     if( !handler->mAccessibilityAdaptor )
821     {
822       DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
823       return;
824     }
825
826     AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
827     if( !accessibilityAdaptor )
828     {
829       DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
830       return;
831     }
832
833     int gestureValue;
834     int xS, yS, xE, yE;
835     int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
836     int eventTime;
837
838     // The string defines the arg-list's respective types.
839     if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
840     {
841       DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
842     }
843
844     DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d  Args: %d,%d,%d,%d  State: %d\n", gestureValue, xS, yS, xE, yE );
845
846     // Create a touch point object.
847     TouchPoint::State touchPointState( TouchPoint::Down );
848     if( state == 0 )
849     {
850       touchPointState = TouchPoint::Down; // Mouse down.
851     }
852     else if( state == 1 )
853     {
854       touchPointState = TouchPoint::Motion; // Mouse move.
855     }
856     else if( state == 2 )
857     {
858       touchPointState = TouchPoint::Up; // Mouse up.
859     }
860     else
861     {
862       touchPointState = TouchPoint::Interrupted; // Error.
863     }
864
865     // Send touch event to accessibility adaptor.
866     TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
867
868     // Perform actions based on received gestures.
869     // Note: This is seperated from the reading so we can have other input readers without changing the below code.
870     switch( gestureValue )
871     {
872       case 0: // OneFingerHover
873       {
874         // Focus, read out.
875         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
876         break;
877       }
878       case 1: // TwoFingersHover
879       {
880         // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
881         accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
882         break;
883       }
884       case 2: // ThreeFingersHover
885       {
886         // Read from top item on screen continuously.
887         accessibilityAdaptor->HandleActionReadFromTopEvent();
888         break;
889       }
890       case 3: // OneFingerFlickLeft
891       {
892         // Move to previous item.
893         accessibilityAdaptor->HandleActionReadPreviousEvent();
894         break;
895       }
896       case 4: // OneFingerFlickRight
897       {
898         // Move to next item.
899         accessibilityAdaptor->HandleActionReadNextEvent();
900         break;
901       }
902       case 5: // OneFingerFlickUp
903       {
904         // Move to previous item.
905         accessibilityAdaptor->HandleActionPreviousEvent();
906         break;
907       }
908       case 6: // OneFingerFlickDown
909       {
910         // Move to next item.
911         accessibilityAdaptor->HandleActionNextEvent();
912         break;
913       }
914       case 7: // TwoFingersFlickUp
915       {
916         // Scroll up the list.
917         accessibilityAdaptor->HandleActionScrollUpEvent();
918         break;
919       }
920       case 8: // TwoFingersFlickDown
921       {
922         // Scroll down the list.
923         accessibilityAdaptor->HandleActionScrollDownEvent();
924         break;
925       }
926       case 9: // TwoFingersFlickLeft
927       {
928         // Scroll left to the previous page
929         accessibilityAdaptor->HandleActionPageLeftEvent();
930         break;
931       }
932       case 10: // TwoFingersFlickRight
933       {
934         // Scroll right to the next page
935         accessibilityAdaptor->HandleActionPageRightEvent();
936         break;
937       }
938       case 11: // ThreeFingersFlickLeft
939       {
940         // Not exist yet
941         break;
942       }
943       case 12: // ThreeFingersFlickRight
944       {
945         // Not exist yet
946         break;
947       }
948       case 13: // ThreeFingersFlickUp
949       {
950         // Not exist yet
951         break;
952       }
953       case 14: // ThreeFingersFlickDown
954       {
955         // Not exist yet
956         break;
957       }
958       case 15: // OneFingerSingleTap
959       {
960         // Focus, read out.
961         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
962         break;
963       }
964       case 16: // OneFingerDoubleTap
965       {
966         // Activate selected item / active edit mode.
967         accessibilityAdaptor->HandleActionActivateEvent();
968         break;
969       }
970       case 17: // OneFingerTripleTap
971       {
972         // Zoom
973         accessibilityAdaptor->HandleActionZoomEvent();
974         break;
975       }
976       case 18: // TwoFingersSingleTap
977       {
978         // Pause/Resume current speech
979         accessibilityAdaptor->HandleActionReadPauseResumeEvent();
980         break;
981       }
982       case 19: // TwoFingersDoubleTap
983       {
984         // Start/Stop current action
985         accessibilityAdaptor->HandleActionStartStopEvent();
986         break;
987       }
988       case 20: // TwoFingersTripleTap
989       {
990         // Read information from indicator
991         accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
992         break;
993       }
994       case 21: // ThreeFingersSingleTap
995       {
996         // Read from top item on screen continuously.
997         accessibilityAdaptor->HandleActionReadFromTopEvent();
998         break;
999       }
1000       case 22: // ThreeFingersDoubleTap
1001       {
1002         // Read from next item continuously.
1003         accessibilityAdaptor->HandleActionReadFromNextEvent();
1004         break;
1005       }
1006       case 23: // ThreeFingersTripleTap
1007       {
1008         // Not exist yet
1009         break;
1010       }
1011       case 24: // OneFingerFlickLeftReturn
1012       {
1013         // Scroll up to the previous page
1014         accessibilityAdaptor->HandleActionPageUpEvent();
1015         break;
1016       }
1017       case 25: // OneFingerFlickRightReturn
1018       {
1019         // Scroll down to the next page
1020         accessibilityAdaptor->HandleActionPageDownEvent();
1021         break;
1022       }
1023       case 26: // OneFingerFlickUpReturn
1024       {
1025         // Move to the first item on screen
1026         accessibilityAdaptor->HandleActionMoveToFirstEvent();
1027         break;
1028       }
1029       case 27: // OneFingerFlickDownReturn
1030       {
1031         // Move to the last item on screen
1032         accessibilityAdaptor->HandleActionMoveToLastEvent();
1033         break;
1034       }
1035       case 28: // TwoFingersFlickLeftReturn
1036       {
1037         // Not exist yet
1038         break;
1039       }
1040       case 29: // TwoFingersFlickRightReturn
1041       {
1042         // Not exist yet
1043         break;
1044       }
1045       case 30: // TwoFingersFlickUpReturn
1046       {
1047         // Not exist yet
1048         break;
1049       }
1050       case 31: // TwoFingersFlickDownReturn
1051       {
1052         // Not exist yet
1053         break;
1054       }
1055       case 32: // ThreeFingersFlickLeftReturn
1056       {
1057         // Not exist yet
1058         break;
1059       }
1060       case 33: // ThreeFingersFlickRightReturn
1061       {
1062         // Not exist yet
1063         break;
1064       }
1065       case 34: // ThreeFingersFlickUpReturn
1066       {
1067         // Not exist yet
1068         break;
1069       }
1070       case 35: // ThreeFingersFlickDownReturn
1071       {
1072         // Not exist yet
1073         break;
1074       }
1075     }
1076   }
1077
1078   void EcoreElDBusInitialisation( void *handle )
1079   {
1080     Eldbus_Object *object;
1081     Eldbus_Proxy *manager;
1082
1083     if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1084     {
1085       DALI_LOG_ERROR( "Unable to get system bus\n" );
1086     }
1087
1088     object = eldbus_object_get( mSystemConnection, BUS, PATH );
1089     if( !object )
1090     {
1091       DALI_LOG_ERROR( "Getting object failed\n" );
1092       return;
1093     }
1094
1095     manager = eldbus_proxy_get( object, INTERFACE );
1096     if( !manager )
1097     {
1098       DALI_LOG_ERROR( "Getting proxy failed\n" );
1099       return;
1100     }
1101
1102     if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1103     {
1104       DALI_LOG_ERROR( "No signal handler returned\n" );
1105     }
1106   }
1107 #endif // DALI_ELDBUS_AVAILABLE
1108
1109   /**
1110    * Called when the source window notifies us the content in clipboard is selected.
1111    */
1112   static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1113   {
1114     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1115     return ECORE_CALLBACK_PASS_ON;
1116   }
1117
1118   /**
1119    * Called when the source window sends us about the selected content.
1120    * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1121    */
1122   static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1123   {
1124     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1125     return ECORE_CALLBACK_PASS_ON;
1126   }
1127
1128   /**
1129   * Called when the source window notifies us the content in clipboard is selected.
1130   */
1131   static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1132   {
1133     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1134
1135     Dali::Clipboard clipboard = Clipboard::Get();
1136     if ( clipboard )
1137     {
1138       Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1139       clipBoardImpl.ExcuteBuffered( true, event );
1140     }
1141     return ECORE_CALLBACK_PASS_ON;
1142   }
1143
1144    /**
1145     * Called when the source window sends us about the selected content.
1146     * For example, when item is selected in the clipboard.
1147     */
1148    static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1149    {
1150      DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1151
1152      EventHandler* handler( (EventHandler*)data );
1153       Dali::Clipboard clipboard = Clipboard::Get();
1154       char *selectionData = NULL;
1155       if ( clipboard )
1156       {
1157         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1158         selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1159       }
1160       if ( selectionData && handler->mClipboardEventNotifier )
1161       {
1162         ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1163         std::string content( selectionData, strlen(selectionData) );
1164
1165         clipboardEventNotifier.SetContent( content );
1166         clipboardEventNotifier.EmitContentSelectedSignal();
1167       }
1168      return ECORE_CALLBACK_PASS_ON;
1169    }
1170
1171   /*
1172   * Called when rotate event is recevied
1173   */
1174   static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1175   {
1176     DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1177
1178     EventHandler* handler( (EventHandler*)data );
1179     Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1180
1181     if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1182     {
1183       return ECORE_CALLBACK_PASS_ON;
1184     }
1185
1186     RotationEvent rotationEvent;
1187     rotationEvent.angle = ev->angle;
1188     rotationEvent.winResize = 0;
1189     rotationEvent.width = ev->w;
1190     rotationEvent.height = ev->h;
1191     handler->SendRotationPrepareEvent( rotationEvent );
1192
1193     return ECORE_CALLBACK_PASS_ON;
1194   }
1195
1196   /*
1197   * Called when detent event is recevied
1198   */
1199   static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1200   {
1201     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1202     EventHandler* handler( (EventHandler*)data );
1203     Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1204     int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1205     int timeStamp = e->timestamp;
1206
1207     WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1208     handler->SendWheelEvent( wheelEvent );
1209     return ECORE_CALLBACK_PASS_ON;
1210   }
1211
1212   /////////////////////////////////////////////////////////////////////////////////////////////////
1213   // Font Callbacks
1214   /////////////////////////////////////////////////////////////////////////////////////////////////
1215   /**
1216    * Called when a font name is changed.
1217    */
1218   static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1219   {
1220     EventHandler* handler = static_cast<EventHandler*>( data );
1221     handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1222   }
1223
1224   /**
1225    * Called when a font size is changed.
1226    */
1227   static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1228   {
1229     EventHandler* handler = static_cast<EventHandler*>( data );
1230     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1231   }
1232
1233   // Data
1234   EventHandler* mHandler;
1235   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1236   Ecore_Wl_Window* mWindow;
1237 #ifdef DALI_ELDBUS_AVAILABLE
1238   Eldbus_Connection* mSystemConnection;
1239 #endif // DALI_ELDBUS_AVAILABLE
1240 };
1241
1242 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1243 : mCoreEventInterface( coreEventInterface ),
1244   mGestureManager( gestureManager ),
1245   mStyleMonitor( StyleMonitor::Get() ),
1246   mDamageObserver( damageObserver ),
1247   mRotationObserver( NULL ),
1248   mDragAndDropDetector( dndDetector ),
1249   mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1250   mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1251   mClipboard( Clipboard::Get() ),
1252   mImpl( NULL ),
1253   mPaused( false )
1254 {
1255   Ecore_Wl_Window* window = 0;
1256
1257   // this code only works with the Ecore RenderSurface so need to downcast
1258   ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1259   if( ecoreSurface )
1260   {
1261     window = ecoreSurface->GetWlWindow();
1262   }
1263
1264   mImpl = new Impl(this, window);
1265 }
1266
1267 EventHandler::~EventHandler()
1268 {
1269   if(mImpl)
1270   {
1271     delete mImpl;
1272   }
1273
1274   mGestureManager.Stop();
1275 }
1276
1277 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1278 {
1279   if(timeStamp < 1)
1280   {
1281     timeStamp = GetCurrentMilliSeconds();
1282   }
1283
1284   Integration::TouchEvent touchEvent;
1285   Integration::HoverEvent hoverEvent;
1286   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1287   if(type != Integration::TouchEventCombiner::DispatchNone )
1288   {
1289     DALI_LOG_INFO(gTouchEventLogFilter, Debug::General, "%d: Device %d: Button state %d (%.2f, %.2f)\n", timeStamp, point.GetDeviceId(), point.GetState(), point.GetLocalPosition().x, point.GetLocalPosition().y);
1290
1291     // First the touch and/or hover event & related gesture events are queued
1292     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1293     {
1294       mCoreEventInterface.QueueCoreEvent( touchEvent );
1295       mGestureManager.SendEvent(touchEvent);
1296     }
1297
1298     if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1299     {
1300       mCoreEventInterface.QueueCoreEvent( hoverEvent );
1301     }
1302
1303     // Next the events are processed with a single call into Core
1304     mCoreEventInterface.ProcessCoreEvents();
1305   }
1306 }
1307
1308 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1309 {
1310   Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1311   if ( physicalKeyboard )
1312   {
1313     if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1314     {
1315       GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1316     }
1317   }
1318
1319   // Create send KeyEvent to Core.
1320   mCoreEventInterface.QueueCoreEvent( keyEvent );
1321   mCoreEventInterface.ProcessCoreEvents();
1322 }
1323
1324 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1325 {
1326   // Create WheelEvent and send to Core.
1327   Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1328   mCoreEventInterface.QueueCoreEvent( event );
1329   mCoreEventInterface.ProcessCoreEvents();
1330 }
1331
1332 void EventHandler::SendEvent( StyleChange::Type styleChange )
1333 {
1334   DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1335   GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1336 }
1337
1338 void EventHandler::SendEvent( const DamageArea& area )
1339 {
1340   mDamageObserver.OnDamaged( area );
1341 }
1342
1343 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1344 {
1345   if( mRotationObserver != NULL )
1346   {
1347     mRotationObserver->OnRotationPrepare( event );
1348     mRotationObserver->OnRotationRequest();
1349   }
1350 }
1351
1352 void EventHandler::SendRotationRequestEvent( )
1353 {
1354   // No need to separate event into prepare and request in wayland
1355 }
1356
1357 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1358 {
1359   Integration::Point convertedPoint( point );
1360   SendEvent(convertedPoint, timeStamp);
1361 }
1362
1363 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1364 {
1365   SendWheelEvent( wheelEvent );
1366 }
1367
1368 void EventHandler::FeedKeyEvent( KeyEvent& event )
1369 {
1370   Integration::KeyEvent convertedEvent( event );
1371   SendEvent( convertedEvent );
1372 }
1373
1374 void EventHandler::FeedEvent( Integration::Event& event )
1375 {
1376   mCoreEventInterface.QueueCoreEvent( event );
1377   mCoreEventInterface.ProcessCoreEvents();
1378 }
1379
1380 void EventHandler::Reset()
1381 {
1382   mCombiner.Reset();
1383
1384   // Any touch listeners should be told of the interruption.
1385   Integration::TouchEvent event;
1386   Integration::Point point;
1387   point.SetState( PointState::INTERRUPTED );
1388   event.AddPoint( point );
1389
1390   // First the touch event & related gesture events are queued
1391   mCoreEventInterface.QueueCoreEvent( event );
1392   mGestureManager.SendEvent( event );
1393
1394   // Next the events are processed with a single call into Core
1395   mCoreEventInterface.ProcessCoreEvents();
1396 }
1397
1398 void EventHandler::Pause()
1399 {
1400   mPaused = true;
1401   Reset();
1402 }
1403
1404 void EventHandler::Resume()
1405 {
1406   mPaused = false;
1407   Reset();
1408 }
1409
1410 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1411 {
1412   mDragAndDropDetector = detector;
1413 }
1414
1415 void EventHandler::SetRotationObserver( RotationObserver* observer )
1416 {
1417   mRotationObserver = observer;
1418 }
1419
1420 } // namespace Adaptor
1421
1422 } // namespace Internal
1423
1424 } // namespace Dali
1425
1426 #pragma GCC diagnostic pop