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