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