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