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