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