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