Add "XF86Exit" keyname to reset imfContext in EventHandler
[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                !strcmp( keyEvent->keyname, "XF86Exit" ) )
650           {
651             ecore_imf_context_reset( imfContext );
652           }
653         }
654       }
655     }
656
657     // If the event wasn't handled then we should send a key event.
658     if ( !eventHandled )
659     {
660       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
661       {
662         std::string keyName( keyEvent->keyname );
663         std::string keyString( "" );
664         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
665         keyCode = (keyCode == -1) ? 0 : keyCode;
666         int modifier( keyEvent->modifiers );
667         unsigned long time = keyEvent->timestamp;
668         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
669           keyCode = atoi(keyEvent->keyname + 8);
670
671         // Ensure key event string is not NULL as keys like SHIFT have a null string.
672         if ( keyEvent->string )
673         {
674           keyString = keyEvent->string;
675         }
676
677         std::string deviceName;
678         Device::Class::Type deviceClass;
679         Device::Subclass::Type deviceSubclass;
680
681         GetDeviceName( keyEvent, deviceName );
682         GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
683         GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
684
685         DALI_LOG_INFO( gImfLogging, Debug::Verbose, "EVENT EcoreEventKeyDown - >>EcoreEventKeyDown deviceName(%s) deviceClass(%d)\n", deviceName.c_str(), deviceClass );
686
687         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, deviceName, deviceClass, deviceSubclass );
688         handler->SendEvent( keyEvent );
689       }
690     }
691
692     return ECORE_CALLBACK_PASS_ON;
693   }
694
695   /**
696    * Called when a key up is received.
697    */
698   static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
699   {
700     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventKeyUp\n" );
701
702     EventHandler* handler( (EventHandler*)data );
703     Ecore_Event_Key *keyEvent( (Ecore_Event_Key*)event );
704     bool eventHandled( false );
705
706     // Device keys like Menu, home, back button must skip ecore_imf_context_filter_event.
707     if ( ! KeyLookup::IsDeviceButton( keyEvent->keyname ) )
708     {
709       Ecore_IMF_Context* imfContext = NULL;
710       Dali::ImfManager imfManager( ImfManager::Get() );
711       if ( imfManager )
712       {
713         imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
714       }
715
716       if ( imfContext )
717       {
718         // We're consuming key up event so we have to pass to IMF so that it can parse it as well.
719         Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;
720         ecoreKeyUpEvent.keyname   = keyEvent->keyname;
721         ecoreKeyUpEvent.key       = keyEvent->key;
722         ecoreKeyUpEvent.string    = keyEvent->string;
723         ecoreKeyUpEvent.compose   = keyEvent->compose;
724         ecoreKeyUpEvent.timestamp = keyEvent->timestamp;
725         ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier ( keyEvent->modifiers );
726         ecoreKeyUpEvent.locks     = EcoreInputModifierToEcoreIMFLock( keyEvent->modifiers );
727         ecoreKeyUpEvent.dev_name  = ecore_device_name_get( keyEvent->dev );
728         ecoreKeyUpEvent.dev_class = static_cast<Ecore_IMF_Device_Class>( ecore_device_class_get( keyEvent->dev ) );
729         ecoreKeyUpEvent.dev_subclass = static_cast<Ecore_IMF_Device_Subclass>( ecore_device_subclass_get( keyEvent->dev ) );
730
731         eventHandled = ecore_imf_context_filter_event( imfContext,
732                                                        ECORE_IMF_EVENT_KEY_UP,
733                                                        (Ecore_IMF_Event *) &ecoreKeyUpEvent );
734       }
735     }
736
737     // If the event wasn't handled then we should send a key event.
738     if ( !eventHandled )
739     {
740       if ( keyEvent->window == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
741       {
742         std::string keyName( keyEvent->keyname );
743         std::string keyString( "" );
744         int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname);
745         keyCode = (keyCode == -1) ? 0 : keyCode;
746         int modifier( keyEvent->modifiers );
747         unsigned long time = keyEvent->timestamp;
748         if (!strncmp(keyEvent->keyname, "Keycode-", 8))
749           keyCode = atoi(keyEvent->keyname + 8);
750
751         // Ensure key event string is not NULL as keys like SHIFT have a null string.
752         if ( keyEvent->string )
753         {
754           keyString = keyEvent->string;
755         }
756
757         std::string deviceName;
758         Device::Class::Type deviceClass;
759         Device::Subclass::Type deviceSubclass;
760
761         GetDeviceName( keyEvent, deviceName );
762         GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
763         GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
764
765         Integration::KeyEvent keyEvent(keyName, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, deviceName, deviceClass, deviceSubclass );
766         handler->SendEvent( keyEvent );
767       }
768     }
769
770     return ECORE_CALLBACK_PASS_ON;
771   }
772
773   /////////////////////////////////////////////////////////////////////////////////////////////////
774   // Window Callbacks
775   /////////////////////////////////////////////////////////////////////////////////////////////////
776
777   /**
778    * Called when the window gains focus.
779    */
780   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
781   {
782     Ecore_Wl_Event_Focus_In* focusInEvent( (Ecore_Wl_Event_Focus_In*)event );
783     EventHandler* handler( (EventHandler*)data );
784
785     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusIn \n" );
786
787     // If the window gains focus and we hid the keyboard then show it again.
788     if ( focusInEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
789     {
790       DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT EcoreEventWindowFocusIn - >>WindowFocusGained \n" );
791
792       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
793       {
794         Dali::ImfManager imfManager( ImfManager::Get() );
795         if ( imfManager )
796         {
797           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
798           if( imfManagerImpl.RestoreAfterFocusLost() )
799           {
800             imfManagerImpl.Activate();
801           }
802         }
803       }
804       Dali::Clipboard clipboard = Clipboard::Get();
805       clipboard.HideClipboard();
806     }
807
808     return ECORE_CALLBACK_PASS_ON;
809   }
810
811   /**
812    * Called when the window loses focus.
813    */
814   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
815   {
816     Ecore_Wl_Event_Focus_Out* focusOutEvent( (Ecore_Wl_Event_Focus_Out*)event );
817     EventHandler* handler( (EventHandler*)data );
818
819     DALI_LOG_INFO( gImfLogging, Debug::General, "EVENT >>EcoreEventWindowFocusOut \n" );
820
821     // If the window loses focus then hide the keyboard.
822     if ( focusOutEvent->win == (unsigned int)ecore_wl_window_id_get(handler->mImpl->mWindow) )
823     {
824       if ( ImfManager::IsAvailable() /* Only get the ImfManager if it's available as we do not want to create it */ )
825       {
826         Dali::ImfManager imfManager( ImfManager::Get() );
827         if ( imfManager )
828         {
829           ImfManager& imfManagerImpl( ImfManager::GetImplementation( imfManager ) );
830           if( imfManagerImpl.RestoreAfterFocusLost() )
831           {
832             imfManagerImpl.Deactivate();
833           }
834         }
835       }
836
837       // Hiding clipboard event will be ignored once because window focus out event is always received on showing clipboard
838       Dali::Clipboard clipboard = Clipboard::Get();
839       if ( clipboard )
840       {
841         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
842         clipBoardImpl.HideClipboard(true);
843       }
844     }
845
846     return ECORE_CALLBACK_PASS_ON;
847   }
848
849   /**
850    * Called when the window is damaged.
851    */
852   static Eina_Bool EcoreEventWindowDamaged(void *data, int type, void *event)
853   {
854     return ECORE_CALLBACK_PASS_ON;
855   }
856
857   /**
858    * Called when the window properties are changed.
859    * We are only interested in the font change.
860    */
861
862
863   /////////////////////////////////////////////////////////////////////////////////////////////////
864   // Drag & Drop Callbacks
865   /////////////////////////////////////////////////////////////////////////////////////////////////
866
867   /**
868    * Called when a dragged item enters our window's bounds.
869    * This is when items are dragged INTO our window.
870    */
871   static Eina_Bool EcoreEventDndEnter( void* data, int type, void* event )
872   {
873     DALI_LOG_INFO( gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndEnter\n" );
874
875     return ECORE_CALLBACK_PASS_ON;
876   }
877
878   /**
879    * Called when a dragged item is moved within our window.
880    * This is when items are dragged INTO our window.
881    */
882   static Eina_Bool EcoreEventDndPosition( void* data, int type, void* event )
883   {
884     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndPosition\n" );
885
886     return ECORE_CALLBACK_PASS_ON;
887   }
888
889   /**
890    * Called when a dragged item leaves our window's bounds.
891    * This is when items are dragged INTO our window.
892    */
893   static Eina_Bool EcoreEventDndLeave( void* data, int type, void* event )
894   {
895     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndLeave\n" );
896
897     return ECORE_CALLBACK_PASS_ON;
898   }
899
900   /**
901    * Called when the dragged item is dropped within our window's bounds.
902    * This is when items are dragged INTO our window.
903    */
904   static Eina_Bool EcoreEventDndDrop( void* data, int type, void* event )
905   {
906     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndDrop\n" );
907
908     return ECORE_CALLBACK_PASS_ON;
909   }
910
911   /**
912    * Called when a dragged item is moved from our window and the target window has done processing it.
913    * This is when items are dragged FROM our window.
914    */
915   static Eina_Bool EcoreEventDndFinished( void* data, int type, void* event )
916   {
917     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndFinished\n" );
918     return ECORE_CALLBACK_PASS_ON;
919   }
920
921   /**
922    * Called when a dragged item is moved from our window and the target window has sent us a status.
923    * This is when items are dragged FROM our window.
924    */
925   static Eina_Bool EcoreEventDndStatus( void* data, int type, void* event )
926   {
927     DALI_LOG_INFO(gDragAndDropLogFilter, Debug::Concise, "EcoreEventDndStatus\n" );
928     return ECORE_CALLBACK_PASS_ON;
929   }
930
931   /**
932    * Called when the client messages (i.e. the accessibility events) are received.
933    */
934   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
935   {
936     return ECORE_CALLBACK_PASS_ON;
937   }
938
939
940   /////////////////////////////////////////////////////////////////////////////////////////////////
941   // ElDBus Accessibility Callbacks
942   /////////////////////////////////////////////////////////////////////////////////////////////////
943
944 #ifdef DALI_ELDBUS_AVAILABLE
945   // Callback for Ecore ElDBus accessibility events.
946   static void OnEcoreElDBusAccessibilityNotification( void *context EINA_UNUSED, const Eldbus_Message *message )
947   {
948     EventHandler* handler = static_cast< EventHandler* >( context );
949     // Ignore any accessibility events when paused.
950     if( handler->mPaused )
951     {
952       return;
953     }
954
955     if( !handler->mAccessibilityAdaptor )
956     {
957       DALI_LOG_ERROR( "Invalid accessibility adaptor\n" );
958       return;
959     }
960
961     AccessibilityAdaptor* accessibilityAdaptor( &AccessibilityAdaptor::GetImplementation( handler->mAccessibilityAdaptor ) );
962     if( !accessibilityAdaptor )
963     {
964       DALI_LOG_ERROR( "Cannot access accessibility adaptor\n" );
965       return;
966     }
967
968     int gestureValue;
969     int xS, yS, xE, yE;
970     int state; // 0 - begin, 1 - ongoing, 2 - ended, 3 - aborted
971     int eventTime;
972
973     // The string defines the arg-list's respective types.
974     if( !eldbus_message_arguments_get( message, "iiiiiiu", &gestureValue, &xS, &yS, &xE, &yE, &state, &eventTime ) )
975     {
976       DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
977     }
978
979     DALI_LOG_INFO( gImfLogging, Debug::General, "Got gesture: Name: %d  Args: %d,%d,%d,%d  State: %d\n", gestureValue, xS, yS, xE, yE );
980
981     // Create a touch point object.
982     TouchPoint::State touchPointState( TouchPoint::Down );
983     if( state == 0 )
984     {
985       touchPointState = TouchPoint::Down; // Mouse down.
986     }
987     else if( state == 1 )
988     {
989       touchPointState = TouchPoint::Motion; // Mouse move.
990     }
991     else if( state == 2 )
992     {
993       touchPointState = TouchPoint::Up; // Mouse up.
994     }
995     else
996     {
997       touchPointState = TouchPoint::Interrupted; // Error.
998     }
999
1000     // Send touch event to accessibility adaptor.
1001     TouchPoint point( 0, touchPointState, (float)xS, (float)yS );
1002
1003     // Perform actions based on received gestures.
1004     // Note: This is seperated from the reading so we can have other input readers without changing the below code.
1005     switch( gestureValue )
1006     {
1007       case 0: // OneFingerHover
1008       {
1009         // Focus, read out.
1010         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1011         break;
1012       }
1013       case 1: // TwoFingersHover
1014       {
1015         // In accessibility mode, scroll action should be handled when the currently focused actor is contained in scrollable control
1016         accessibilityAdaptor->HandleActionScrollEvent( point, GetCurrentMilliSeconds() );
1017         break;
1018       }
1019       case 2: // ThreeFingersHover
1020       {
1021         // Read from top item on screen continuously.
1022         accessibilityAdaptor->HandleActionReadFromTopEvent();
1023         break;
1024       }
1025       case 3: // OneFingerFlickLeft
1026       {
1027         // Move to previous item.
1028         accessibilityAdaptor->HandleActionReadPreviousEvent();
1029         break;
1030       }
1031       case 4: // OneFingerFlickRight
1032       {
1033         // Move to next item.
1034         accessibilityAdaptor->HandleActionReadNextEvent();
1035         break;
1036       }
1037       case 5: // OneFingerFlickUp
1038       {
1039         // Move to previous item.
1040         accessibilityAdaptor->HandleActionPreviousEvent();
1041         break;
1042       }
1043       case 6: // OneFingerFlickDown
1044       {
1045         // Move to next item.
1046         accessibilityAdaptor->HandleActionNextEvent();
1047         break;
1048       }
1049       case 7: // TwoFingersFlickUp
1050       {
1051         // Scroll up the list.
1052         accessibilityAdaptor->HandleActionScrollUpEvent();
1053         break;
1054       }
1055       case 8: // TwoFingersFlickDown
1056       {
1057         // Scroll down the list.
1058         accessibilityAdaptor->HandleActionScrollDownEvent();
1059         break;
1060       }
1061       case 9: // TwoFingersFlickLeft
1062       {
1063         // Scroll left to the previous page
1064         accessibilityAdaptor->HandleActionPageLeftEvent();
1065         break;
1066       }
1067       case 10: // TwoFingersFlickRight
1068       {
1069         // Scroll right to the next page
1070         accessibilityAdaptor->HandleActionPageRightEvent();
1071         break;
1072       }
1073       case 11: // ThreeFingersFlickLeft
1074       {
1075         // Not exist yet
1076         break;
1077       }
1078       case 12: // ThreeFingersFlickRight
1079       {
1080         // Not exist yet
1081         break;
1082       }
1083       case 13: // ThreeFingersFlickUp
1084       {
1085         // Not exist yet
1086         break;
1087       }
1088       case 14: // ThreeFingersFlickDown
1089       {
1090         // Not exist yet
1091         break;
1092       }
1093       case 15: // OneFingerSingleTap
1094       {
1095         // Focus, read out.
1096         accessibilityAdaptor->HandleActionReadEvent( (unsigned int)xS, (unsigned int)yS, true /* allow read again */ );
1097         break;
1098       }
1099       case 16: // OneFingerDoubleTap
1100       {
1101         // Activate selected item / active edit mode.
1102         accessibilityAdaptor->HandleActionActivateEvent();
1103         break;
1104       }
1105       case 17: // OneFingerTripleTap
1106       {
1107         // Zoom
1108         accessibilityAdaptor->HandleActionZoomEvent();
1109         break;
1110       }
1111       case 18: // TwoFingersSingleTap
1112       {
1113         // Pause/Resume current speech
1114         accessibilityAdaptor->HandleActionReadPauseResumeEvent();
1115         break;
1116       }
1117       case 19: // TwoFingersDoubleTap
1118       {
1119         // Start/Stop current action
1120         accessibilityAdaptor->HandleActionStartStopEvent();
1121         break;
1122       }
1123       case 20: // TwoFingersTripleTap
1124       {
1125         // Read information from indicator
1126         accessibilityAdaptor->HandleActionReadIndicatorInformationEvent();
1127         break;
1128       }
1129       case 21: // ThreeFingersSingleTap
1130       {
1131         // Read from top item on screen continuously.
1132         accessibilityAdaptor->HandleActionReadFromTopEvent();
1133         break;
1134       }
1135       case 22: // ThreeFingersDoubleTap
1136       {
1137         // Read from next item continuously.
1138         accessibilityAdaptor->HandleActionReadFromNextEvent();
1139         break;
1140       }
1141       case 23: // ThreeFingersTripleTap
1142       {
1143         // Not exist yet
1144         break;
1145       }
1146       case 24: // OneFingerFlickLeftReturn
1147       {
1148         // Scroll up to the previous page
1149         accessibilityAdaptor->HandleActionPageUpEvent();
1150         break;
1151       }
1152       case 25: // OneFingerFlickRightReturn
1153       {
1154         // Scroll down to the next page
1155         accessibilityAdaptor->HandleActionPageDownEvent();
1156         break;
1157       }
1158       case 26: // OneFingerFlickUpReturn
1159       {
1160         // Move to the first item on screen
1161         accessibilityAdaptor->HandleActionMoveToFirstEvent();
1162         break;
1163       }
1164       case 27: // OneFingerFlickDownReturn
1165       {
1166         // Move to the last item on screen
1167         accessibilityAdaptor->HandleActionMoveToLastEvent();
1168         break;
1169       }
1170       case 28: // TwoFingersFlickLeftReturn
1171       {
1172         // Not exist yet
1173         break;
1174       }
1175       case 29: // TwoFingersFlickRightReturn
1176       {
1177         // Not exist yet
1178         break;
1179       }
1180       case 30: // TwoFingersFlickUpReturn
1181       {
1182         // Not exist yet
1183         break;
1184       }
1185       case 31: // TwoFingersFlickDownReturn
1186       {
1187         // Not exist yet
1188         break;
1189       }
1190       case 32: // ThreeFingersFlickLeftReturn
1191       {
1192         // Not exist yet
1193         break;
1194       }
1195       case 33: // ThreeFingersFlickRightReturn
1196       {
1197         // Not exist yet
1198         break;
1199       }
1200       case 34: // ThreeFingersFlickUpReturn
1201       {
1202         // Not exist yet
1203         break;
1204       }
1205       case 35: // ThreeFingersFlickDownReturn
1206       {
1207         // Not exist yet
1208         break;
1209       }
1210     }
1211   }
1212
1213   void EcoreElDBusInitialisation( void *handle )
1214   {
1215     Eldbus_Object *object;
1216     Eldbus_Proxy *manager;
1217
1218     if( !( mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM) ) )
1219     {
1220       DALI_LOG_ERROR( "Unable to get system bus\n" );
1221     }
1222
1223     object = eldbus_object_get( mSystemConnection, BUS, PATH );
1224     if( !object )
1225     {
1226       DALI_LOG_ERROR( "Getting object failed\n" );
1227       return;
1228     }
1229
1230     manager = eldbus_proxy_get( object, INTERFACE );
1231     if( !manager )
1232     {
1233       DALI_LOG_ERROR( "Getting proxy failed\n" );
1234       return;
1235     }
1236
1237     if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", OnEcoreElDBusAccessibilityNotification, handle ) )
1238     {
1239       DALI_LOG_ERROR( "No signal handler returned\n" );
1240     }
1241   }
1242 #endif // DALI_ELDBUS_AVAILABLE
1243
1244   /**
1245    * Called when the source window notifies us the content in clipboard is selected.
1246    */
1247   static Eina_Bool EcoreEventSelectionClear( void* data, int type, void* event )
1248   {
1249     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionClear\n" );
1250     return ECORE_CALLBACK_PASS_ON;
1251   }
1252
1253   /**
1254    * Called when the source window sends us about the selected content.
1255    * For example, when dragged items are dragged INTO our window or when items are selected in the clipboard.
1256    */
1257   static Eina_Bool EcoreEventSelectionNotify( void* data, int type, void* event )
1258   {
1259     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventSelectionNotify\n" );
1260     return ECORE_CALLBACK_PASS_ON;
1261   }
1262
1263   /**
1264   * Called when the source window notifies us the content in clipboard is selected.
1265   */
1266   static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
1267   {
1268     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataSend\n" );
1269
1270     Dali::Clipboard clipboard = Clipboard::Get();
1271     if ( clipboard )
1272     {
1273       Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1274       clipBoardImpl.ExcuteBuffered( true, event );
1275     }
1276     return ECORE_CALLBACK_PASS_ON;
1277   }
1278
1279    /**
1280     * Called when the source window sends us about the selected content.
1281     * For example, when item is selected in the clipboard.
1282     */
1283    static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
1284    {
1285      DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDataReceive\n" );
1286
1287      EventHandler* handler( (EventHandler*)data );
1288       Dali::Clipboard clipboard = Clipboard::Get();
1289       char *selectionData = NULL;
1290       if ( clipboard )
1291       {
1292         Clipboard& clipBoardImpl( GetImplementation( clipboard ) );
1293         selectionData = clipBoardImpl.ExcuteBuffered( false, event );
1294       }
1295       if ( selectionData && handler->mClipboardEventNotifier )
1296       {
1297         ClipboardEventNotifier& clipboardEventNotifier( ClipboardEventNotifier::GetImplementation( handler->mClipboardEventNotifier ) );
1298         std::string content( selectionData, strlen(selectionData) );
1299
1300         clipboardEventNotifier.SetContent( content );
1301         clipboardEventNotifier.EmitContentSelectedSignal();
1302       }
1303      return ECORE_CALLBACK_PASS_ON;
1304    }
1305
1306   /*
1307   * Called when rotate event is recevied
1308   */
1309   static Eina_Bool EcoreEventRotate( void* data, int type, void* event )
1310   {
1311     DALI_LOG_INFO( gSelectionEventLogFilter, Debug::Concise, "EcoreEventRotate\n" );
1312
1313     EventHandler* handler( (EventHandler*)data );
1314     Ecore_Wl_Event_Window_Rotate* ev( (Ecore_Wl_Event_Window_Rotate*)event );
1315
1316     if( ev->win != (unsigned int)ecore_wl_window_id_get( handler->mImpl->mWindow ) )
1317     {
1318       return ECORE_CALLBACK_PASS_ON;
1319     }
1320
1321     RotationEvent rotationEvent;
1322     rotationEvent.angle = ev->angle;
1323     rotationEvent.winResize = 0;
1324
1325     if( ev->angle == 0 || ev->angle == 180 )
1326     {
1327       rotationEvent.width = ev->w;
1328       rotationEvent.height = ev->h;
1329     }
1330     else
1331     {
1332       rotationEvent.width = ev->h;
1333       rotationEvent.height = ev->w;
1334     }
1335
1336     handler->SendRotationPrepareEvent( rotationEvent );
1337
1338     return ECORE_CALLBACK_PASS_ON;
1339   }
1340
1341   /*
1342   * Called when detent event is recevied
1343   */
1344   static Eina_Bool EcoreEventDetent( void* data, int type, void* event )
1345   {
1346     DALI_LOG_INFO(gSelectionEventLogFilter, Debug::Concise, "EcoreEventDetent\n" );
1347     EventHandler* handler( (EventHandler*)data );
1348     Ecore_Event_Detent_Rotate *e((Ecore_Event_Detent_Rotate *)event);
1349     int direction = (e->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1350     int timeStamp = e->timestamp;
1351
1352     WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp );
1353     handler->SendWheelEvent( wheelEvent );
1354     return ECORE_CALLBACK_PASS_ON;
1355   }
1356
1357   /////////////////////////////////////////////////////////////////////////////////////////////////
1358   // Font Callbacks
1359   /////////////////////////////////////////////////////////////////////////////////////////////////
1360   /**
1361    * Called when a font name is changed.
1362    */
1363   static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
1364   {
1365     EventHandler* handler = static_cast<EventHandler*>( data );
1366     handler->SendEvent( StyleChange::DEFAULT_FONT_CHANGE );
1367   }
1368
1369   /**
1370    * Called when a font size is changed.
1371    */
1372   static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
1373   {
1374     EventHandler* handler = static_cast<EventHandler*>( data );
1375     handler->SendEvent( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1376   }
1377
1378   void ConvertTouchPosition( Integration::Point& point )
1379   {
1380     Vector2 position = point.GetScreenPosition();
1381     Vector2 convertedPosition;
1382
1383     switch( mRotationAngle )
1384     {
1385       case 90:
1386       {
1387         convertedPosition.x = mWindowWidth - position.y;
1388         convertedPosition.y = position.x;
1389         break;
1390       }
1391       case 180:
1392       {
1393         convertedPosition.x = mWindowWidth - position.x;
1394         convertedPosition.y = mWindowHeight - position.y;
1395         break;
1396       }
1397       case 270:
1398       {
1399         convertedPosition.x = position.y;
1400         convertedPosition.y = mWindowHeight - position.x;
1401         break;
1402       }
1403       default:
1404       {
1405         convertedPosition = position;
1406         break;
1407       }
1408     }
1409
1410     point.SetScreenPosition( convertedPosition );
1411   }
1412
1413   // Data
1414   EventHandler* mHandler;
1415   std::vector<Ecore_Event_Handler*> mEcoreEventHandler;
1416   Ecore_Wl_Window* mWindow;
1417   int mRotationAngle;
1418   int mWindowWidth;
1419   int mWindowHeight;
1420 #ifdef DALI_ELDBUS_AVAILABLE
1421   Eldbus_Connection* mSystemConnection;
1422 #endif // DALI_ELDBUS_AVAILABLE
1423 };
1424
1425 EventHandler::EventHandler( RenderSurface* surface, CoreEventInterface& coreEventInterface, GestureManager& gestureManager, DamageObserver& damageObserver, DragAndDropDetectorPtr dndDetector )
1426 : mCoreEventInterface( coreEventInterface ),
1427   mGestureManager( gestureManager ),
1428   mStyleMonitor( StyleMonitor::Get() ),
1429   mDamageObserver( damageObserver ),
1430   mRotationObserver( NULL ),
1431   mDragAndDropDetector( dndDetector ),
1432   mAccessibilityAdaptor( AccessibilityAdaptor::Get() ),
1433   mClipboardEventNotifier( ClipboardEventNotifier::Get() ),
1434   mClipboard( Clipboard::Get() ),
1435   mImpl( NULL ),
1436   mPaused( false )
1437 {
1438   Ecore_Wl_Window* window = 0;
1439
1440   // this code only works with the Ecore RenderSurface so need to downcast
1441   ECore::WindowRenderSurface* ecoreSurface = dynamic_cast< ECore::WindowRenderSurface* >( surface );
1442   if( ecoreSurface )
1443   {
1444     window = ecoreSurface->GetWlWindow();
1445   }
1446
1447   mImpl = new Impl(this, window);
1448 }
1449
1450 EventHandler::~EventHandler()
1451 {
1452   if(mImpl)
1453   {
1454     delete mImpl;
1455   }
1456
1457   mGestureManager.Stop();
1458 }
1459
1460 void EventHandler::SendEvent(Integration::Point& point, unsigned long timeStamp)
1461 {
1462   if(timeStamp < 1)
1463   {
1464     timeStamp = GetCurrentMilliSeconds();
1465   }
1466
1467   mImpl->ConvertTouchPosition( point );
1468
1469   Integration::TouchEvent touchEvent;
1470   Integration::HoverEvent hoverEvent;
1471   Integration::TouchEventCombiner::EventDispatchType type = mCombiner.GetNextTouchEvent(point, timeStamp, touchEvent, hoverEvent);
1472   if(type != Integration::TouchEventCombiner::DispatchNone )
1473   {
1474     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);
1475
1476     // First the touch and/or hover event & related gesture events are queued
1477     if(type == Integration::TouchEventCombiner::DispatchTouch || type == Integration::TouchEventCombiner::DispatchBoth)
1478     {
1479       mCoreEventInterface.QueueCoreEvent( touchEvent );
1480       mGestureManager.SendEvent(touchEvent);
1481     }
1482
1483     if(type == Integration::TouchEventCombiner::DispatchHover || type == Integration::TouchEventCombiner::DispatchBoth)
1484     {
1485       mCoreEventInterface.QueueCoreEvent( hoverEvent );
1486     }
1487
1488     // Next the events are processed with a single call into Core
1489     mCoreEventInterface.ProcessCoreEvents();
1490   }
1491 }
1492
1493 void EventHandler::SendEvent(Integration::KeyEvent& keyEvent)
1494 {
1495   Dali::PhysicalKeyboard physicalKeyboard = PhysicalKeyboard::Get();
1496   if ( physicalKeyboard )
1497   {
1498     if ( ! KeyLookup::IsDeviceButton( keyEvent.keyName.c_str() ) )
1499     {
1500       GetImplementation( physicalKeyboard ).KeyReceived( keyEvent.time > 1 );
1501     }
1502   }
1503
1504   // Create send KeyEvent to Core.
1505   mCoreEventInterface.QueueCoreEvent( keyEvent );
1506   mCoreEventInterface.ProcessCoreEvents();
1507 }
1508
1509 void EventHandler::SendWheelEvent( WheelEvent& wheelEvent )
1510 {
1511   // Create WheelEvent and send to Core.
1512   Integration::WheelEvent event( static_cast< Integration::WheelEvent::Type >(wheelEvent.type), wheelEvent.direction, wheelEvent.modifiers, wheelEvent.point, wheelEvent.z, wheelEvent.timeStamp );
1513   mCoreEventInterface.QueueCoreEvent( event );
1514   mCoreEventInterface.ProcessCoreEvents();
1515 }
1516
1517 void EventHandler::SendEvent( StyleChange::Type styleChange )
1518 {
1519   DALI_ASSERT_DEBUG( mStyleMonitor && "StyleMonitor Not Available" );
1520   GetImplementation( mStyleMonitor ).StyleChanged(styleChange);
1521 }
1522
1523 void EventHandler::SendEvent( const DamageArea& area )
1524 {
1525   mDamageObserver.OnDamaged( area );
1526 }
1527
1528 void EventHandler::SendRotationPrepareEvent( const RotationEvent& event )
1529 {
1530   if( mRotationObserver != NULL )
1531   {
1532     mImpl->mRotationAngle = event.angle;
1533     mImpl->mWindowWidth = event.width;
1534     mImpl->mWindowHeight = event.height;
1535
1536     mRotationObserver->OnRotationPrepare( event );
1537     mRotationObserver->OnRotationRequest();
1538   }
1539 }
1540
1541 void EventHandler::SendRotationRequestEvent( )
1542 {
1543   // No need to separate event into prepare and request in wayland
1544 }
1545
1546 void EventHandler::FeedTouchPoint( TouchPoint& point, int timeStamp)
1547 {
1548   Integration::Point convertedPoint( point );
1549   SendEvent(convertedPoint, timeStamp);
1550 }
1551
1552 void EventHandler::FeedWheelEvent( WheelEvent& wheelEvent )
1553 {
1554   SendWheelEvent( wheelEvent );
1555 }
1556
1557 void EventHandler::FeedKeyEvent( KeyEvent& event )
1558 {
1559   Integration::KeyEvent convertedEvent( event );
1560   SendEvent( convertedEvent );
1561 }
1562
1563 void EventHandler::FeedEvent( Integration::Event& event )
1564 {
1565   mCoreEventInterface.QueueCoreEvent( event );
1566   mCoreEventInterface.ProcessCoreEvents();
1567 }
1568
1569 void EventHandler::Reset()
1570 {
1571   mCombiner.Reset();
1572
1573   // Any touch listeners should be told of the interruption.
1574   Integration::TouchEvent event;
1575   Integration::Point point;
1576   point.SetState( PointState::INTERRUPTED );
1577   event.AddPoint( point );
1578
1579   // First the touch event & related gesture events are queued
1580   mCoreEventInterface.QueueCoreEvent( event );
1581   mGestureManager.SendEvent( event );
1582
1583   // Next the events are processed with a single call into Core
1584   mCoreEventInterface.ProcessCoreEvents();
1585 }
1586
1587 void EventHandler::Pause()
1588 {
1589   mPaused = true;
1590   Reset();
1591 }
1592
1593 void EventHandler::Resume()
1594 {
1595   mPaused = false;
1596   Reset();
1597 }
1598
1599 void EventHandler::SetDragAndDropDetector( DragAndDropDetectorPtr detector )
1600 {
1601   mDragAndDropDetector = detector;
1602 }
1603
1604 void EventHandler::SetRotationObserver( RotationObserver* observer )
1605 {
1606   mRotationObserver = observer;
1607 }
1608
1609 } // namespace Adaptor
1610
1611 } // namespace Internal
1612
1613 } // namespace Dali
1614
1615 #pragma GCC diagnostic pop