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