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