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