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